Skip to content

Commit

Permalink
Merge pull request mozilla#10869 from Rob--W/issue-10645-preserve-htt…
Browse files Browse the repository at this point in the history
…p-referer-again

Restore referrer preserving functionality in Chrome 72+
  • Loading branch information
timvandermeij authored May 29, 2019
2 parents f652cf8 + 32c1a1d commit 5adb323
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions extensions/chromium/preserve-referer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,26 @@ var g_requestHeaders = {};
// g_referrers[tabId][frameId] = referrer of PDF frame.
var g_referrers = {};

var extraInfoSpecWithHeaders; // = ['requestHeaders', 'extraHeaders']

(function() {
var requestFilter = {
urls: ['*://*/*'],
types: ['main_frame', 'sub_frame'],
};
chrome.webRequest.onSendHeaders.addListener(function(details) {
g_requestHeaders[details.requestId] = details.requestHeaders;
}, requestFilter, ['requestHeaders']);
function registerListener(extraInfoSpec) {
extraInfoSpecWithHeaders = extraInfoSpec;
// May throw if the given extraInfoSpec is unsupported.
chrome.webRequest.onSendHeaders.addListener(function(details) {
g_requestHeaders[details.requestId] = details.requestHeaders;
}, requestFilter, extraInfoSpec);
}
try {
registerListener(['requestHeaders', 'extraHeaders']);
} catch (e) {
// "extraHeaders" is not supported in Chrome 71 and earlier.
registerListener(['requestHeaders']);
}
chrome.webRequest.onBeforeRedirect.addListener(forgetHeaders, requestFilter);
chrome.webRequest.onCompleted.addListener(forgetHeaders, requestFilter);
chrome.webRequest.onErrorOccurred.addListener(forgetHeaders, requestFilter);
Expand Down Expand Up @@ -105,7 +117,7 @@ chrome.runtime.onConnect.addListener(function onReceivePort(port) {
urls: [data.requestUrl],
types: ['xmlhttprequest'],
tabId: tabId,
}, ['blocking', 'requestHeaders']);
}, ['blocking', ...extraInfoSpecWithHeaders]);
}
// Acknowledge the message, and include the latest referer for this frame.
port.postMessage(referer);
Expand Down

0 comments on commit 5adb323

Please sign in to comment.