0

I want my extension to change the document.referrer of certain webpages, but searching for this leads to documentation on how to change the Referrer in the HTTP request headers.

Is there any way to use an extension to change document.referrer, preferably before the javascript(s) of a webpage loads?

Currently I refresh pages where I want the document.referrer altered with window.location.replace(window.location.href), but this generates a noticeable flicker, and only can change the referrer to the current page.

SylphFeather
  • 425
  • 4
  • 7

1 Answers1

0

override.js:

Object.defineProperty(Document.prototype, 'referrer', {
  get() {
    return 'foo';
  },
});

This should be put in page context at document_start, there are several methods.

For ManifestV3 the most reliable method is registerContentScripts: example. Specify the correct pattern in matches and optionally add allFrames: true; matchOriginAsFallback: true if the site uses frames.

Note that due to a bug in Chrome the sites can extract the original getter and call it on the main document to get the real referrer. The workarounds are mentioned in the report and aren't simple.

wOxxOm
  • 65,848
  • 11
  • 132
  • 136