fix issue on firefox where the extension can seeminly only set one cookie in the response, by packing the 'shouldLog' value into the base64 encoded bitfield

This commit is contained in:
Peter Snyder 2017-10-17 23:11:59 -05:00
parent b9cf1b9a8e
commit bc8774ecc0
4 changed files with 28 additions and 13 deletions

View file

@ -124,18 +124,21 @@
// of the URL being requested.
const matchingDomainRule = domainMatcherLib.matchUrl(Object.keys(domainRules), url);
const standardsToBlock = domainRules[matchingDomainRule || defaultKey];
const shouldLogOption = ["shouldLog"];
const options = Object.keys(standards);
const packedValues = packingLib.pack(options, standardsToBlock);
const options = Object.keys(standards).concat(shouldLogOption);
const standardsToBlockWithShouldLogOption = shouldLog
? standardsToBlock.concat(shouldLogOption)
: standardsToBlock;
const packedValues = packingLib.pack(
options,
standardsToBlockWithShouldLogOption
);
details.responseHeaders.push({
name: "Set-Cookie",
value: `wam-standards=${packedValues}`
});
details.responseHeaders.push({
name: "Set-Cookie",
value: `wam-log=${shouldLog ? "true" : "false"}`
value: `wam-temp-cookie=${packedValues}`
});
return {

View file

@ -8,17 +8,26 @@
const doc = window.document;
const script = doc.createElement('script');
const rootElm = doc.head || doc.documentElement;
const shouldLogValue = "shouldLog";
const standardsCookieKey = "wam-standards";
const standardsCookieKey = "wam-temp-cookie";
const {packingLib, standards} = window.WEB_API_MANAGER;
const options = Object.keys(standards);
const optionsWithShouldLog = options.concat([shouldLogValue]);
const packedValues = Cookies.get(standardsCookieKey);
const standardsToBlock = packingLib.unpack(options, packedValues);
const unpackedValues = packingLib.unpack(optionsWithShouldLog, packedValues);
Cookies.remove(standardsCookieKey);
const shouldLogCookieKey = "wam-log";
const shouldLog = Cookies.get(shouldLogCookieKey);
Cookies.remove(shouldLogCookieKey);
let shouldLog;
const standardsToBlock = unpackedValues;
const indexOfShouldLog = unpackedValues.indexOf(shouldLogValue);
if (indexOfShouldLog === -1) {
shouldLog = false;
} else {
shouldLog = true;
standardsToBlock.splice(indexOfShouldLog, 1);
}
const code = `
window.WEB_API_MANAGER_PAGE = {

View file

@ -146,11 +146,13 @@
parentRef[lastPropertyName] = defaultBlockingProxy;
return true;
} catch (e) {
if (shouldLog) {
console.log("Error instrumenting " + keyPath + ": " + e);
}
return false;
}
};

View file

@ -19,6 +19,7 @@
"privacy",
"storage",
"tabs",
"cookies",
"unlimitedStorage",
"webNavigation",
"webRequest",