[CRX] Disable fetch in Chrome 60-

Chrome 60 and earlier does not include credentials (cookies) in requests
made with fetch, regardless of extension permissions. This was fixed in
61.0.3138.0 by
2e231cf052

This patch disables the fetch backend in all affected Chrome versions.
The browser detection is done by checking for a change that coincides
with the release of Chrome 61.

Test case:
1. Copy the `isChromeWithFetchCredentials` function from the patch.
2. Run it in the JS console of Chrome and verify the return value.

Verified results:
- 49.0.2623.75 - false (earliest supported version by us)
- 60.0.3112.90 - false (last major version affected by bug)
- 61.0.3163.100 - true (first major version without bug)
- 65.0.3325.146 - true (current stable)

Test case 2:
1. Build the extension (`gulp chromium`) and load it in Chrome.
2. Open the developer tools, and open any PDF file.
3. In the "Network tab" of the developer tools, look at "request type".
   In Chrome 60-: Should be "xhr"
   In Chrome 61+: Should be "fetch"
This commit is contained in:
Rob Wu 2018-03-08 18:00:35 +01:00
parent c33bf800cc
commit db428004f4

View File

@ -52,8 +52,21 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
} else if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) {
let PDFNetworkStream = require('./display/network.js').PDFNetworkStream;
let PDFFetchStream;
let isChromeWithFetchCredentials = function() {
// fetch does not include credentials until Chrome 61.0.3138.0 and later.
// https://chromium.googlesource.com/chromium/src/+/2e231cf052ca5e68e22baf0008ac9e5e29121707
try {
// Indexed properties on window are read-only in Chrome 61.0.3151.0+
// https://chromium.googlesource.com/chromium/src.git/+/58ab4a971b06dec13e4edf9de8382ca6847f6190
window[999] = 123; // should throw. Note: JS strict mode MUST be enabled.
delete window[999];
return false;
} catch (e) {
return true;
}
};
if (typeof Response !== 'undefined' && 'body' in Response.prototype &&
typeof ReadableStream !== 'undefined') {
typeof ReadableStream !== 'undefined' && isChromeWithFetchCredentials()) {
PDFFetchStream = require('./display/fetch_stream.js').PDFFetchStream;
}
pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {