Skip to content

js: add document.referrer - #339

Merged
tannevaled merged 1 commit into
mainfrom
js-document-referrer
Nov 1, 2026
Merged

tannevaled merged 1 commit into
mainfrom
js-document-referrer

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Summary

Continuing round 199's methodology shift: instead of cold-grepping CSS/JS
feature names across sites, render real live pages through this engine's
own Fetch+RenderDocument with JSLog capturing every compile/runtime
error, then look at what actually fired.

  • A sweep of 10 real sites (news, SaaS, framework-marketing homepages)
    found document.referrer.indexOf(hostname) throwing TypeError: Cannot read property 'indexOf' of undefined or null at trackPageview
    identically on both vuejs.org and astro.build — the same
    third-party script (cdn.usefathom.com/script.js) on two otherwise-
    unrelated sites, the same "one popular library, many sites break the
    same way" shape document.location (round 199, js: wire document.location to the same object as window.location #338) had.
  • grep -rn referrer js/ (excluding tests) returned nothing at all — the
    property genuinely did not exist.
  • Fixed: a new read-only accessor on document (js/dom.go, next to
    the existing hidden/visibilityState accessors) — always the empty
    string, per HTML Standard §7.8.1's own "no referring document" case,
    which this engine's single-URL fetch model always is.
  • Verified end to end against both real live sites, before/after: the
    TypeError disappears from JSLog on both; vuejs.org's own separate,
    unrelated, already-documented dynamic-import() SyntaxError is
    untouched, confirming the fix's effect is precisely scoped.
  • A second lead, not pursued this round: stripe.com's own bundle
    calls <canvas>.getContext(...), unimplemented. Larger in scope than a
    single property stub — flagged for a dedicated future round.
  • Also confirmed, correctly out of scope: top-level await (bbc.com,
    nextjs.org) and dynamic import() (vuejs.org, svelte.dev) are genuine
    upstream goja parser gaps, no parser in this repo to patch.

Test plan

  • go test ./... — all green, no coverage-gate regression
  • js/js_test.go's new TestDocumentReferrerIsEmptyString — calls
    .indexOf() on the result directly, the real trigger's own exact
    shape
  • Independently re-rendered both real live sites before/after: the
    TypeError line disappears, nothing else changes
  • go build ./... && go vet ./... clean

🤖 Generated with Claude Code

Per HTML Standard 7.8.1: Document.referrer returns the referring
document's URL, or the empty string when there is none - not
undefined.

Continuing round 199's methodology shift: instead of cold-grepping
CSS/JS feature names across sites, render real live pages through
this engine's own Fetch+RenderDocument with JSLog capturing every
compile/runtime error, then look at what actually fired. A sweep of
10 real sites (news, SaaS, framework-marketing homepages) found
document.referrer.indexOf(hostname) throwing "TypeError: Cannot read
property 'indexOf' of undefined or null at trackPageview" identically
on BOTH vuejs.org and astro.build - the same third-party script
(cdn.usefathom.com/script.js) on two otherwise-unrelated sites, the
same "one popular library, many sites break the same way" shape
document.location (round 199) had.

grep -rn referrer js/ (excluding tests) returned nothing at all - the
property genuinely did not exist. Fixed with a new read-only accessor
on document, next to the existing hidden/visibilityState ones: always
the empty string, the spec's own "no referring document" case, which
this engine's single-URL fetch model always is.

Verified end to end against both real live sites, before/after: the
TypeError disappears from JSLog on both; vuejs.org's own separate,
unrelated, already-documented dynamic-import() SyntaxError (a genuine
upstream goja parser gap) is untouched, confirming the fix's effect
is precisely scoped.

A second lead found by the same sweep, not pursued this round:
stripe.com's own bundle calls <canvas>.getContext(...), which this
engine's js/ package does not implement at all. Larger in scope than
a single property stub - flagged for a dedicated future round.

Also confirmed, correctly out of scope: top-level await (bbc.com,
nextjs.org) and dynamic import() (vuejs.org, svelte.dev) are genuine
upstream goja parser gaps, no parser in this repo to patch.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 23faee0 into main Nov 1, 2026
13 checks passed
@tannevaled
tannevaled deleted the js-document-referrer branch November 1, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant