Skip to content

Commit

Permalink
fix: use feature detection so browser compatability isn't reduced
Browse files Browse the repository at this point in the history
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"]}
  • Loading branch information
warren-bank committed Jan 29, 2022
1 parent 71e4b54 commit 3e39527
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "privacy-pass",
"version": "3.6.2",
"version": "3.6.3",
"private": true,
"contributors": [
"Suphanat Chunhapanya <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "__MSG_appName__",
"description": "__MSG_appDescription__",
"version": "3.6.2",
"version": "3.6.3",
"manifest_version": 2,
"default_locale": "en",
"icons": {
Expand Down
60 changes: 36 additions & 24 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,42 @@ chrome.tabs.query({ active: true, currentWindow: true }, function (tabs: chrome.
}
});

chrome.webRequest.onBeforeRequest.addListener(handleBeforeRequest, { urls: ['<all_urls>'] }, [
'blocking',
'requestBody',
'extraHeaders',
]);

chrome.webRequest.onBeforeSendHeaders.addListener(handleBeforeSendHeaders, { urls: ['<all_urls>'] }, [
'blocking',
'requestHeaders',
'extraHeaders',
]);

chrome.webRequest.onHeadersReceived.addListener(handleHeadersReceived, { urls: ['<all_urls>'] }, [
'blocking',
'responseHeaders',
'extraHeaders',
]);

chrome.webRequest.onCompleted.addListener(handleOnCompleted, { urls: ['<all_urls>'] }, [
'responseHeaders',
'extraHeaders',
]);

chrome.webRequest.onErrorOccurred.addListener(handleOnErrorOccurred, { urls: ['<all_urls>'] });
chrome.webRequest.onBeforeRequest.addListener(
handleBeforeRequest,
{ urls: ['<all_urls>'] },
((<any>chrome.webRequest).OnBeforeRequestOptions !== undefined)
? Object.values((<any>chrome.webRequest).OnBeforeRequestOptions)
: ['blocking', 'requestBody']
);

chrome.webRequest.onBeforeSendHeaders.addListener(
handleBeforeSendHeaders,
{ urls: ['<all_urls>'] },
((<any>chrome.webRequest).OnBeforeSendHeadersOptions !== undefined)
? Object.values((<any>chrome.webRequest).OnBeforeSendHeadersOptions)
: ['blocking', 'requestHeaders']
);

chrome.webRequest.onHeadersReceived.addListener(
handleHeadersReceived,
{ urls: ['<all_urls>'] },
((<any>chrome.webRequest).OnHeadersReceivedOptions !== undefined)
? Object.values((<any>chrome.webRequest).OnHeadersReceivedOptions)
: ['blocking', 'responseHeaders']
);

chrome.webRequest.onCompleted.addListener(
handleOnCompleted,
{ urls: ['<all_urls>'] },
((<any>chrome.webRequest).OnCompletedOptions !== undefined)
? Object.values((<any>chrome.webRequest).OnCompletedOptions)
: ['responseHeaders']
);

chrome.webRequest.onErrorOccurred.addListener(
handleOnErrorOccurred,
{ urls: ['<all_urls>'] },
);

chrome.cookies.onChanged.addListener(handleChangedCookies);

Expand Down

0 comments on commit 3e39527

Please sign in to comment.