Skip to content

Commit 3e39527

Browse files
committed
fix: use feature detection so browser compatability isn't reduced
notes: ====== * only Chrome 72+ recognize the "extraHeaders" option value - both Firefox and older versions of Chrome will throw an error if this value is included when adding a listener to a "chrome.webRequest" event annoyances: =========== * the typescript definitions got in the way * "@types/chrome" doesn't define types for any of the "On---Options" classes in "chrome.webRequest" * for this reason, any time they need to be accessed.. "chrome.webRequest" needs to be cast to "any" * a future version of "@types/chrome" will hopefully allow this casting to be removed observations regarding status of browser compatability: ======================================================= * tested in Chrome 85 - Cloudflare * working: - issuing of tokens - redeeming of tokens - hCaptcha * working: - issuing of tokens - redeeming of tokens * tested in Chrome 30 - Cloudflare * not working: - issuing of tokens - hCaptcha * working: - issuing of tokens - redeeming of tokens * note: uses 2x tokens per bypassed captcha * tested in Firefox 97 - Cloudflare * working: - issuing of tokens - redeeming of tokens - hCaptcha * not working: - issuing of tokens to do: ====== * investigate why hCaptcha isn't issuing tokens in Firefox - it's behaving as though the original request had been cancelled - the request to issue tokens is being correctly sent to the provider, but it's being returned with a 403 status code: {"success":false,"error-codes":["invalid-data"]}
1 parent 71e4b54 commit 3e39527

File tree

3 files changed

+38
-26
lines changed

3 files changed

+38
-26
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "privacy-pass",
3-
"version": "3.6.2",
3+
"version": "3.6.3",
44
"private": true,
55
"contributors": [
66
"Suphanat Chunhapanya <[email protected]>",

public/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "__MSG_appName__",
33
"description": "__MSG_appDescription__",
4-
"version": "3.6.2",
4+
"version": "3.6.3",
55
"manifest_version": 2,
66
"default_locale": "en",
77
"icons": {

src/background/index.ts

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,42 @@ chrome.tabs.query({ active: true, currentWindow: true }, function (tabs: chrome.
7272
}
7373
});
7474

75-
chrome.webRequest.onBeforeRequest.addListener(handleBeforeRequest, { urls: ['<all_urls>'] }, [
76-
'blocking',
77-
'requestBody',
78-
'extraHeaders',
79-
]);
80-
81-
chrome.webRequest.onBeforeSendHeaders.addListener(handleBeforeSendHeaders, { urls: ['<all_urls>'] }, [
82-
'blocking',
83-
'requestHeaders',
84-
'extraHeaders',
85-
]);
86-
87-
chrome.webRequest.onHeadersReceived.addListener(handleHeadersReceived, { urls: ['<all_urls>'] }, [
88-
'blocking',
89-
'responseHeaders',
90-
'extraHeaders',
91-
]);
92-
93-
chrome.webRequest.onCompleted.addListener(handleOnCompleted, { urls: ['<all_urls>'] }, [
94-
'responseHeaders',
95-
'extraHeaders',
96-
]);
97-
98-
chrome.webRequest.onErrorOccurred.addListener(handleOnErrorOccurred, { urls: ['<all_urls>'] });
75+
chrome.webRequest.onBeforeRequest.addListener(
76+
handleBeforeRequest,
77+
{ urls: ['<all_urls>'] },
78+
((<any>chrome.webRequest).OnBeforeRequestOptions !== undefined)
79+
? Object.values((<any>chrome.webRequest).OnBeforeRequestOptions)
80+
: ['blocking', 'requestBody']
81+
);
82+
83+
chrome.webRequest.onBeforeSendHeaders.addListener(
84+
handleBeforeSendHeaders,
85+
{ urls: ['<all_urls>'] },
86+
((<any>chrome.webRequest).OnBeforeSendHeadersOptions !== undefined)
87+
? Object.values((<any>chrome.webRequest).OnBeforeSendHeadersOptions)
88+
: ['blocking', 'requestHeaders']
89+
);
90+
91+
chrome.webRequest.onHeadersReceived.addListener(
92+
handleHeadersReceived,
93+
{ urls: ['<all_urls>'] },
94+
((<any>chrome.webRequest).OnHeadersReceivedOptions !== undefined)
95+
? Object.values((<any>chrome.webRequest).OnHeadersReceivedOptions)
96+
: ['blocking', 'responseHeaders']
97+
);
98+
99+
chrome.webRequest.onCompleted.addListener(
100+
handleOnCompleted,
101+
{ urls: ['<all_urls>'] },
102+
((<any>chrome.webRequest).OnCompletedOptions !== undefined)
103+
? Object.values((<any>chrome.webRequest).OnCompletedOptions)
104+
: ['responseHeaders']
105+
);
106+
107+
chrome.webRequest.onErrorOccurred.addListener(
108+
handleOnErrorOccurred,
109+
{ urls: ['<all_urls>'] },
110+
);
99111

100112
chrome.cookies.onChanged.addListener(handleChangedCookies);
101113

0 commit comments

Comments
 (0)