fix(play): absorb malformed HTML + warn when runner script is swallowed - #435
Draft
caugner wants to merge 3 commits into
Draft
fix(play): absorb malformed HTML + warn when runner script is swallowed#435caugner wants to merge 3 commits into
caugner wants to merge 3 commits into
Conversation
caugner
force-pushed
the
1440-playground-runner-breakout-guard
branch
from
July 17, 2026 14:46
20f59b0 to
b5e6b5c
Compare
caugner
force-pushed
the
1440-playground-runner-breakout-guard
branch
from
September 3, 2026 11:40
b5e6b5c to
104c389
Compare
caugner
force-pushed
the
1440-playground-runner-breakout-guard
branch
2 times, most recently
from
September 3, 2026 19:42
e3ddac4 to
1d919f0
Compare
caugner
force-pushed
the
1440-playground-runner-breakout-guard
branch
2 times, most recently
from
September 9, 2026 14:12
f839e5c to
791199b
Compare
caugner
added this pull request to stack #516
September 9, 2026 14:12
caugner
removed this pull request from stack #516
September 9, 2026 14:38
caugner
added this pull request to stack #517
September 9, 2026 14:39
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. Mirrors mdn/fred.
Assert that the runner output carries the `mdn-play-js` and `mdn-play-js-end` markers and that the swallow detection runs from the `<head>` after `DOMContentLoaded`. Ported from `mdn/fred`, where the test lives outside the vendored directory.
caugner
force-pushed
the
1440-playground-runner-breakout-guard
branch
from
September 9, 2026 14:41
f17d1c7 to
cf56ea8
Compare
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-runner-breakout-guard
branch
from
September 9, 2026 15:27
ecc49dc to
27d1047
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 from mdn/fred#1705. ⚠️ )
Description
Update the mirrored Playground runner (
cloud-function/src/internal/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.Ports the unit test from mdn/fred#1705 to
cloud-function/src/internal/play/index.test.js, next to the runner. The sync workflow only overwritesindex.js, so the test survives future syncs.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 (mdn/fred#1440).This file serves the Playground runner in review and production, so the fix only takes effect outside local dev once this lands.
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>Related issues and pull requests
Mirrors mdn/fred#1705, the fix for mdn/fred#1440.
Depends on: #437.