Skip to content

Commit

Permalink
Add extraHeaders into extraInfos for Chrome
Browse files Browse the repository at this point in the history
Chrome needs the extraHeaders flag in extraInfos to read the Referer
header.
  • Loading branch information
ppopth committed Feb 2, 2022
1 parent cb79846 commit 977e0c3
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,23 @@ declare global {
}
}

declare let browser: any;

window.ACTIVE_TAB_ID = chrome.tabs.TAB_ID_NONE;
window.TABS = new Map<number, Tab>();

function getBrowser() {
if (typeof chrome !== 'undefined') {
if (typeof browser !== 'undefined') {
return 'Firefox';
} else {
return 'Chrome';
}
} else {
return 'Edge';
}
}

/* Listeners for navigator */

chrome.tabs.onActivated.addListener(handleActivated);
Expand Down Expand Up @@ -57,10 +71,14 @@ chrome.webRequest.onBeforeRequest.addListener(handleBeforeRequest, { urls: ['<al
'blocking',
]);

const extraInfos = ['requestHeaders', 'blocking'];
if (getBrowser() === 'Chrome') {
extraInfos.push('extraHeaders');
}
chrome.webRequest.onBeforeSendHeaders.addListener(
handleBeforeSendHeaders,
{ urls: ['<all_urls>'] },
['requestHeaders', 'blocking'],
extraInfos,
);

chrome.webRequest.onHeadersReceived.addListener(handleHeadersReceived, { urls: ['<all_urls>'] }, [
Expand Down

0 comments on commit 977e0c3

Please sign in to comment.