fix(playground): absorb malformed HTML + warn when runner script is swallowed - #1705
Open
caugner wants to merge 2 commits into
Open
fix(playground): absorb malformed HTML + warn when runner script is swallowed#1705caugner wants to merge 2 commits into
caugner wants to merge 2 commits into
Conversation
Contributor
|
ba69f51 was deployed to: https://fred-pr1705.review.mdn.allizom.net/ |
caugner
commented
Jul 17, 2026
caugner
force-pushed
the
1440-playground-detect-swallowed-script
branch
from
July 17, 2026 14:25
24b04be to
9623022
Compare
caugner
force-pushed
the
1440-playground-detect-swallowed-script
branch
from
July 17, 2026 14:49
9623022 to
4f7eb53
Compare
caugner
marked this pull request as ready for review
July 17, 2026 14:51
LeoMcA
requested changes
Aug 19, 2026
caugner
force-pushed
the
1440-playground-detect-swallowed-script
branch
from
September 2, 2026 16:13
4f7eb53 to
72cb4a7
Compare
caugner
commented
Sep 3, 2026
caugner
force-pushed
the
1440-playground-detect-swallowed-script
branch
from
September 3, 2026 09:36
fe7f962 to
dd9f0e1
Compare
caugner
marked this pull request as draft
September 3, 2026 09:37
caugner
force-pushed
the
1440-playground-detect-swallowed-script
branch
from
September 3, 2026 09:46
dd9f0e1 to
c64793c
Compare
caugner
marked this pull request as ready for review
September 4, 2026 11:42
caugner
marked this pull request as draft
September 8, 2026 08:13
caugner
force-pushed
the
1440-playground-detect-swallowed-script
branch
from
September 9, 2026 13:38
c64793c to
90e3191
Compare
caugner
marked this pull request as ready for review
September 9, 2026 14:05
caugner
force-pushed
the
1440-playground-detect-swallowed-script
branch
from
September 9, 2026 15:27
9711bc3 to
ad0fca6
Compare
Add `id="mdn-play-js"` and `id="mdn-play-js-end"` markers to the runner script and the script following it, and check from the head after `DOMContentLoaded` that both are present as script elements. If either is missing, log a console warning. Unclosed or malformed tags in the HTML input can absorb the runner script, so the JavaScript never executes and the playground silently does nothing.
…lags Insert `<!-- "" '' -->` after the HTML so an unclosed tag, attribute value, or comment ends there instead of swallowing the runner script. Set `window.__mdnPlayJsStarted` and `window.__mdnPlayJsEnded` around the runner and check those in `<head>`, since the script elements disappear when user JS replaces the body's children (a false positive in live samples using `document.body.innerHTML`).
caugner
force-pushed
the
1440-playground-detect-swallowed-script
branch
from
September 9, 2026 15:38
ad0fca6 to
138b9be
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(⚠️ Mirrored to mdn/dex#435. ⚠️ )
Description
Fix the Playground runner (
vendor/yari/libs/play/index.js) so malformed HTML no longer swallows the user's JS, and warn when it still does:<!-- "" '' -->after the HTML, which closes an unclosed tag, attribute value, or comment before the runner script.window.__mdnPlayJsStartedin a script before the runner andwindow.__mdnPlayJsEndedin the script after it.<head>check onDOMContentLoadedthat warns viaconsole.warnif either flag is missing.test/unit/play/runner.test.js).Motivation
Ensure a typo like
<oin the HTML no longer renders the JS as text, and that users get a hint in the remaining cases (e.g. an unclosed<textarea>), where the JS silently does not run.Additional details
Flags instead of marker elements: user JS that replaces the body's children (e.g.
document.body.innerHTML = ..., as several live samples do) removes the script elements but not the flags.Verified with headless Chrome:
<p>ok</p>annn <o jwj,<div class=", unclosed<!--document.bodychildren<textarea>,<template>,<math>The file is mirrored in
mdn/dex(cloud-function/src/internal/play/index.js), which serves the runner in deployed environments, so the fix only takes effect there once mdn/dex#435 lands.Related issues and pull requests
Fixes #1440.