From 32dbd716b1f00dfa47ab57d3e3fc9a67f41efbc3 Mon Sep 17 00:00:00 2001 From: Navid EMAD Date: Sun, 17 May 2026 16:57:02 +0200 Subject: [PATCH] Apply fragment parse-mode to DOMParser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes the DOMParser gap left as a follow-up in the previous review-fix commit. DOMParser.parseFromString built its target Document via the frame's parser without touching `_parse_mode`, so `Build.created` → `linkAddedCallback` → `loadExternalStylesheet` saw `_parse_mode == .document` and fetched/registered sheets on the LIVE frame document for every stylesheet link in the parsed string. Bracket both the text/html and XML branches with the same fragment parse-mode `parseHtmlAsChildren` uses. The existing gate in `loadExternalStylesheet` already short-circuits on .fragment, so no change is needed there. Side benefits: parser-emitted scripts in DOMParser content stop reaching `scriptAddedCallback` against the live frame, default-script injection skips DOMParser content, and mutation observers on the live document no longer fan out for parsed nodes — all of which match what DOMParser should do per spec. Regression test extended to cover the DOMParser path alongside the existing innerHTML case. Refs #2343 --- .../tests/css/external_stylesheet.html | 28 +++++++++++-------- src/browser/webapi/DOMParser.zig | 11 ++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/browser/tests/css/external_stylesheet.html b/src/browser/tests/css/external_stylesheet.html index 10b38042..a98520ad 100644 --- a/src/browser/tests/css/external_stylesheet.html +++ b/src/browser/tests/css/external_stylesheet.html @@ -125,22 +125,28 @@ { // Stylesheet links parsed via innerHTML / outerHTML / // insertAdjacentHTML / Range.createContextualFragment /