Repository navigation
js: add document.referrer - #339
Merged
Merged
Conversation
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>
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
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+RenderDocumentwithJSLogcapturing every compile/runtimeerror, then look at what actually fired.
found
document.referrer.indexOf(hostname)throwingTypeError: Cannot read property 'indexOf' of undefined or null at trackPageviewidentically 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 — theproperty genuinely did not exist.
document(js/dom.go, next tothe existing
hidden/visibilityStateaccessors) — always the emptystring, per HTML Standard §7.8.1's own "no referring document" case,
which this engine's single-URL fetch model always is.
TypeErrordisappears fromJSLogon both; vuejs.org's own separate,unrelated, already-documented dynamic-
import()SyntaxErrorisuntouched, confirming the fix's effect is precisely scoped.
stripe.com's own bundlecalls
<canvas>.getContext(...), unimplemented. Larger in scope than asingle property stub — flagged for a dedicated future round.
await(bbc.com,nextjs.org) and dynamic
import()(vuejs.org, svelte.dev) are genuineupstream
gojaparser gaps, no parser in this repo to patch.Test plan
go test ./...— all green, no coverage-gate regressionjs/js_test.go's newTestDocumentReferrerIsEmptyString— calls.indexOf()on the result directly, the real trigger's own exactshape
TypeErrorline disappears, nothing else changesgo build ./... && go vet ./...clean🤖 Generated with Claude Code