Repository navigation
fix(browser): resolve XLink and SVG prefixes in XHTML dom_urls - #1683
Merged
Merged
Conversation
DOMSnapshot has no namespace URI. HTML documents still use the parser's local names. In XHTML and other XML documents, resolve in-scope xmlns declarations so an element is SVG only in the SVG namespace, and report any XLink href as href when plain href is absent. Refs morluto#1586
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Owner
|
Thanks for tracing this to XHTML namespace declarations, @sathariels. Resolving the SVG and XLink prefixes from in-scope |
2 tasks done
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.
Summary
inspect-web-pagestill omitsdom_urlsentries for some SVG links in XHTML. There is no linked issue for this change. It is the follow-up CassieFox23 reported on #1602 (comment) after #1602 merged: a prefixed<svg:a xlink:href>in an XHTML page is a link in Chrome and still gets no entry. This resolves element and attribute prefixes from in-scopexmlnsdeclarations in XML documents only. HTML documents are unchanged. Refs #1586.Problem and expected behavior
#1602 reports a literal
xlink:hrefwhen an element or ancestor is namedsvgand a closer ancestor is notforeignObject. Chrome's XML parser keeps prefixes, so an XHTML document's nodes arehtml,svg:svg, andsvg:a, and none of those names matchsvg.Smallest trigger: an XHTML page (
application/xhtml+xml) containing<svg:a xlink:href="/xl-pa1">.metadata.dom_urlshas no entry. Chrome treats that node as a link (namespaceURIis the SVG namespace,href.baseValis set, and it matches:any-link).Expected, still stored as attribute
href, with the same base URL and origin policy as a plainhref:<svg:a xlink:href>in XHTML, including one nested undersvg:foreignObject<svg:a xlink:href>with nosvgparent, when thesvgprefix is bound to the SVG namespace<svg:image xlink:href><a p:href>whenpis any prefix bound tohttp://www.w3.org/1999/xlinkPlain
hrefwins even when it is empty. The first duplicate attribute wins. These stay unreported: an XHTML<a>or<h:a>insideforeignObjectwhose namespace is XHTML, and<bogus:svg>whose prefix is bound to a namespace other than SVG. HTML documents keep today's literalxlink:hrefbehavior.Change and scope
DOMSnapshot.captureSnapshotstill has no namespace field. It does keepxmlnsandxmlns:pas attributes. HTML documents show an uppercase document element (HTML); XHTML and other XML documents show lowercasehtmlor a prefixed root.HTML documents (document element
HTML, and the existing synthetic snapshots whose root is unprefixedsvg) still use the per-document ancestry cache: SVG context is the namesvg, stopped byforeignObject. The fallback attribute remains the literal namexlink:href.XML documents resolve prefixes in one walk and store the result in that same per-document cache. Each node reuses its parent's namespace scope when it has no local
xmlnsdeclaration, so a deep tree does not walk ancestors again and does not copy a map per level. A cyclic parent chain fails closed. The default namespace applies to unprefixed elements and not to unprefixed attributes. An element is SVG only when its resolved namespace ishttp://www.w3.org/2000/svg. The fallback is the firstp:hrefwhose prefix resolves tohttp://www.w3.org/1999/xlink. It is used only when plainhrefis absent, and it is reported ashref. Node names and attribute names are not rewritten.Intentionally not included:
dom_urls[].attributechange.browserObservationSchemas.tsis unchanged.svgroot with noxmlnsas XML. Those snapshots stay on the HTML-parser path so fix(browser): report SVG xlink:href links in dom_urls #1602's tests stay valid.Contract and boundary impact
domMetadatain the browser CDP capture adapter, while normalizing aDOMSnapshot.captureSnapshotresult intometadata.dom_urls. Prefix resolution is owned bysrc/browser/CdpCaptureDomSvg.tsat that same stage. No earlier capture stage changes.dom_urls[].attributeenum stayshref | src | action | formaction | poster. XHTML pages that previously omitted prefixed SVG links now include those URLs ashref.HTMLvshtml) andxmlnsattributes preserved on the snapshot.hrefvalues (resolved URL plusdestination_scope). Observed node names and attribute names stay prefixed (svg:a,xlink:href).docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs andskills/; edit authored instructions inskill-src/and never commit build outputs): none. No schema, catalog, package, or skill source change.Evidence and regression coverage
Executed against
upstream/main(3749ccec) with the new tests applied and the production change reverted, then again with the change.src/browser/CdpCaptureDocuments.baseUrl.test.ts(prefixedsvg:aandsvg:image, orphansvg:a,svg:aundersvg:foreignObject, XHTML<a>and<h:a>excluded, custom XLink prefix, literalxlinkrebound to another namespace, href wins including empty href, outside-policy origin,bogus:svg, HTML document unchanged, xmlns on the element itself, forward ancestor, 4000 nested elements under 1000ms).tests/boundary/browser/cdpSvgXlinkHref.test.ts(real headless Chrome, page served asapplication/xhtml+xml).3749ccec,npm run test:focused -- src/browser/CdpCaptureDocuments.baseUrl.test.ts tests/boundary/browser/cdpSvgXlinkHref.test.tsfailed 9 tests and passed 36. The XHTML Chrome test received 2hrefentries (the plainhrefand the emptyhref) and not the 8 entries the page should produce. Prefixed snapshot fixtures produced[]instead of the SVG URL. The custom-prefix fixture reportedhttps://app.example.test/not-xlinkfrom the literal namexlink:hrefinstead ofhttps://app.example.test/xl-custom. The HTML-document test and the plain-href precedence test passed on that base because plainhrefis already collected for every element and HTML names are unchanged.metadata.dom_urlsfromCdpBrowserProvider.inspectPage, the same records the CLI and MCP adapters return. For<svg:a xlink:href="/xl-pa1">the entry is attributehref, url{origin}/xl-pa1, destination_scopeapproved. The DOM node stayssvg:awith attribute namexlink:href. The CLI and MCP routes were not invoked.verify:browserlane,inspect-web-pageCLI, and MCP route were not run. No real-world SVG page beyond the fixture.For evidence-bearing changes:
Validation performed
npm ci(Node v24.18.0, npm 11.16.0) - passed.npm run format:checkon unmodifiedupstream/main3749ccec- passed (All matched files use the correct format, 2491 files). The earlier unrelated format failure is not present on this base.npm run test:focused -- src/browser/CdpCaptureDocuments.baseUrl.test.ts tests/boundary/browser/cdpSvgXlinkHref.test.tson that base with these tests - failed, 9 failed / 36 passed.REA_BROWSER_NO_SANDBOX=true.npm run check- passed. Turbo typecheck, lint, format:check, knip, and metadata:check succeeded. Lint reported 707 warnings and 0 errors in unrelated files. Architecture guards passed across 1110 source files.format:checkpassed on this branch as well (All matched files use the correct format, 2492 files).npm run verify:test-discovery- passed (Discovered all 811 test files exactly once).npm run check:fast- passed on push.Compatibility, safety, and release
dom_urlsoutput is unchanged. XHTML pages gainhrefentries that were previously missing. Callers that assumed those links were absent will now see them, with the same attribute enum and destination policy.REA_BROWSER_NO_SANDBOX=truebecause this environment requires it. The test skips when no Chrome-family executable is installed. Hopper and Ghidra are not involved.outside_policyorunsupported. No new process authority. The boundary test starts a local Chrome and a loopback fixture server and tears both down.Review checklist
type(scope): outcome.