Repository navigation
dom-shim, page-script: document identity, dialog focus, frame windows, style preloads, and viewport meta - #207
Open
BernardoPe wants to merge 9 commits into
Conversation
BernardoPe
requested review from
LuisDuarte1,
celso,
jonnyparris and
ruifigueira
as code owners
November 23, 2026 12:24
BernardoPe
force-pushed
the
bpereira/compat-dom-shim-page-script
branch
from
November 23, 2026 12:48
33a6b49 to
450ea31
Compare
BernardoPe
force-pushed
the
bpereira/compat-dom-shim-page-script
branch
from
November 23, 2026 13:43
450ea31 to
53bde43
Compare
ruifigueira
reviewed
Nov 24, 2026
BernardoPe
force-pushed
the
bpereira/compat-dom-shim-page-script
branch
from
November 24, 2026 18:51
53bde43 to
d16ac9e
Compare
BernardoPe
force-pushed
the
bpereira/compat-dom-shim-page-script
branch
from
November 24, 2026 22:20
d16ac9e to
90ac50e
Compare
ruifigueira
approved these changes
Nov 25, 2026
BernardoPe
force-pushed
the
bpereira/compat-dom-shim-page-script
branch
from
November 25, 2026 22:16
90ac50e to
7d2050c
Compare
ruifigueira
approved these changes
Nov 25, 2026
ruifigueira
left a comment
Collaborator
There was a problem hiding this comment.
beep-boop-rui-agent-🤖
The blocking findings are fixed. Approving.
BernardoPe
force-pushed
the
bpereira/compat-dom-shim-page-script
branch
2 times, most recently
from
November 26, 2026 17:47
ac19aaa to
d1757c5
Compare
ruifigueira
approved these changes
Nov 27, 2026
Four web-platform behavior gaps: `document.constructor` was the live DocumentImpl, whose inherited hasInstance accepted any node. Bootstrap 4's tooltip guard compares against it, so `span instanceof document.constructor` was true and the guard threw on every element on dominos.com. The constructor now points at the Document interface. showModal() left focus on the page, so a modal could not be operated by keyboard. It now runs the HTML dialog focusing steps: the autofocus element, else the first focusable descendant, else the dialog. A `download` anchor followed a blob: or data: target as a navigation and replaced the document. It now keeps the current document per HTML's hyperlink download rules. structuredClone copied a DOM node into a broken plain object instead of throwing DataCloneError, so a page that cloned a node saw a silent success. Signed-off-by: bpereira <bpereira@cloudflare.com>
A link with target="_blank" (or any non-reserved target name) opened in another browsing context on the web; Kitesurf navigated the current tab instead, losing the page the visitor was on (cvc.com.br's Promoções link). SVG elements also had no timing API, so a page that calls pauseAnimations()/unpauseAnimations() unconditionally threw a TypeError and aborted its script (soundcloud.com). The methods now exist on Element.prototype with a receiver check, since SVG elements are plain Element instances. Nothing animates yet; the TODO records that. The SVG constructor stubs now inherit from SVGElement, which inherits from Element, so SVGSVGElement.prototype resolves those members the way the real interface hierarchy does. Signed-off-by: bpereira <bpereira@cloudflare.com>
Elements created from an iframe's document are ParsedElements, which had no style property. A page that set `el.style.cssText` on one threw "Cannot set properties of undefined" (w3schools.com's fast-cmp listener). The inline style declaration only needs getAttribute and setAttribute, so ParsedElement reuses Element's implementation through a named export rather than duplicating it. page-script: cap inserted scripts per script, not only in total The 8 MiB budget was cumulative, so a page whose inserted scripts add up past it silently lost the rest (jotform.com skipped a 6.7 MB embedded agent). One script is still capped at 8 MiB, which bounds what boa buffers and parses; the page total is now 32 MiB. Signed-off-by: bpereira <bpereira@cloudflare.com>
…dows The iframe contentWindow facade carried a hand-kept list of constructors, so `frame.contentWindow.HTMLScriptElement` was undefined. Osano's bundle reads `HTMLScriptElement.prototype.src` through that window and threw "Cannot read properties of undefined (reading 'prototype')" on life360.com and rentgrata.com. The decorator now copies every global that is a constructor (a function with a prototype), read from its descriptor so accessors such as `document` are not invoked, alongside the non-constructor window helpers. Cross-origin facades are built elsewhere and still hide them. Signed-off-by: bpereira <bpereira@cloudflare.com>
A parser-inserted `<link rel="preload" as="style">` with an `onload` handler (the standard non-blocking CSS pattern that swaps `rel` to `"stylesheet"` on load) never fetched and never fired `load`, leaving dialogs and sections unstyled on sites like blogs.com. Start the preload fetch when the initial document is parsed and dispatch `load` or `error` on the `<link>` element per HTML's preload link processing. Signed-off-by: bpereira <bpereira@cloudflare.com>
Pages that declare a fixed layout viewport width such as `<meta name="viewport" content="width=1120">` (e.g. wikidata.org) were still laid out at the narrower device viewport width (375px), causing horizontal overflow and a mismatched `window.innerWidth` / `clientWidth`. Parse explicit numeric `width=<px>` from `<meta name="viewport">` in `resolveLayoutViewport`, widening the layout viewport to `max(deviceWidth, metaWidth)` and scaling height proportionally while leaving `width=device-width` and wider desktop viewports unchanged. https://drafts.csswg.org/css-viewport/#viewport-meta Signed-off-by: bpereira <bpereira@cloudflare.com>
…erfaces Copying every function with a prototype from `globalThis` onto same-origin iframe facades leaked non-element constructors such as `BroadcastChannel` and `EventTarget` across realms, causing cross-realm WPT tests (`abort-signal-timeout`, `reason-constructor`, `detached-iframe`) to fail or time out. Restore the explicit standard global list and copy only `HTML*Element`, `SVG*Element`, and `MathML*Element` constructors dynamically. Signed-off-by: bpereira <bpereira@cloudflare.com>
Signed-off-by: bpereira <bpereira@cloudflare.com>
…oad, and structuredClone review findings Gate meta[name=viewport] numeric width on mobile emulation (passed from Emulation.setDeviceMetricsOverride through NavigateOptions, setViewport, and Page.startScreencast) and clamp the layout viewport to engine side and pixel caps. Keep _blank and unmatched named-target anchors navigating the current tab until popup targets exist, route matching named targets to their <iframe name> via querySelectorAll, and restrict download suppression to blob:/data: URLs. Replace duck-typed structuredClone node detection with a prototype-backed isDomNode check across NodeBase/Attr/Detached/Parsed nodes, traversing arrays without Object.keys and inspecting Map/Set entries. Pass crossorigin mode and non-load-blocking mode on parser style preloads, cache element interface names for same-origin frame decoration, and require autofocus candidates in showModal() to be focusable. Signed-off-by: bpereira <bpereira@cloudflare.com>
BernardoPe
force-pushed
the
bpereira/compat-dom-shim-page-script
branch
from
November 27, 2026 19:55
d1757c5 to
4984e0a
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.
Part 2 of 5 in a stacked compatibility series (stacked on #206).
Changes
structuredClone(dom-shim,page-script):document.constructoratDocumentsoelement instanceof document.constructorisfalse(fixes Bootstrap 4 tooltip guard throwing on dominos.com).showModal()so opened modals receive keyboard focus (fixes Escape dismissal on excalidraw.com).downloadanchors targetingblob:,data:, or same-origin URLs (fixes feathericons.com).DataCloneErrorinstructuredCloneinstead of cloning them into plain objects (fixes docs.stripe.com).target="_blank"anchors and SVG timing API (page-script):_blankor non-reserved browsing context names (fixes cvc.com.br).pauseAnimations()/unpauseAnimations()on SVG elements with receiver checks andTODOfor SMIL animation playback, and fix SVG constructor prototype inheritance (fixes soundcloud.com)..styleand inserted-script budget (dom-shim,page-script):.styleonParsedElementby reusingElement's inline style declaration (fixes w3schools.com).contentWindowconstructors (page-script): Copy every realm constructor (read via property descriptors so accessors are not invoked) onto same-origin frame windows alongside existing window helpers, while keeping cross-origin facades restricted (fixes OsanoHTMLScriptElement.prototypereads on life360.com and rentgrata.com).page-script): Fetch parser-inserted<link rel="preload" as="style">and dispatchload/errorsoonloadhandlers that swaprelto"stylesheet"run (fixes blogs.com).widthin<meta name="viewport">(page-script): Widen narrow mobile viewports tomax(deviceWidth, metaWidth)with proportional height scaling while leavingwidth=device-widthand wider desktop viewports unchanged (fixes wikidata.org).Verification
packages/engine/test/e2e/document-constructor-identity.e2e.test.tspackages/engine/test/e2e/dialog-modal-focus.e2e.test.tspackages/engine/test/e2e/download-anchor-no-navigation.e2e.test.tspackages/engine/test/e2e/structured-clone-node-rejection.e2e.test.tspackages/engine/test/e2e/anchor-target-blank-no-navigation.e2e.test.tspackages/engine/test/e2e/svg-animation-methods.e2e.test.tspackages/engine/test/e2e/frame-document-inline-style.e2e.test.tspackages/engine/test/e2e/iframe-window-constructors.e2e.test.tspackages/engine/test/e2e/preload-style-link.e2e.test.tspackages/engine/test/e2e/meta-viewport-width.e2e.test.ts