mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Ensure FLoC is opt-in by default
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1553 This commit ensures FLoC is opt-in. The generic filter `*##+js(no-floc)` in "uBlock filters -- Privacy" ensures the feature is disabled when using default settings/lists. Users can opt-in to FLoC by adding a generic exception filter to their custom filters, `#@#+js(no-floc)`; or they can opt-in only for a specific set of websites through a more specific exception filter: example.com,shopping.example#@#+js(no-floc)
This commit is contained in:
parent
5a48917b80
commit
bfdc81e9e4
@ -668,12 +668,18 @@
|
|||||||
/// no-floc.js
|
/// no-floc.js
|
||||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/1553
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/1553
|
||||||
(function() {
|
(function() {
|
||||||
if ( document.interestCohort instanceof Function === false ) { return; }
|
if ( Document instanceof Object === false ) { return; }
|
||||||
document.interestCohort = new Proxy(document.interestCohort, {
|
if ( Document.prototype.interestCohort instanceof Function === false ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Document.prototype.interestCohort = new Proxy(
|
||||||
|
Document.prototype.interestCohort,
|
||||||
|
{
|
||||||
apply: function() {
|
apply: function() {
|
||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
@ -382,6 +382,10 @@
|
|||||||
return out.join('\n');
|
return out.join('\n');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
api.hasScriptlet = function(hostname, exceptionBit, scriptlet) {
|
||||||
|
return scriptletDB.hasStr(hostname, exceptionBit, scriptlet);
|
||||||
|
};
|
||||||
|
|
||||||
api.injectNow = function(details) {
|
api.injectNow = function(details) {
|
||||||
if ( typeof details.frameId !== 'number' ) { return; }
|
if ( typeof details.frameId !== 'number' ) { return; }
|
||||||
const request = {
|
const request = {
|
||||||
|
@ -173,6 +173,35 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasStr(hostname, exceptionBit, value) {
|
||||||
|
let found = false;
|
||||||
|
for (;;) {
|
||||||
|
let iHn = this.hostnameToSlotIdMap.get(hostname);
|
||||||
|
if ( iHn !== undefined ) {
|
||||||
|
do {
|
||||||
|
const strId = this.hostnameSlots[iHn+0];
|
||||||
|
if ( this.strSlots[strId >>> this.nBits] === value ) {
|
||||||
|
if ( (strId & exceptionBit) !== 0 ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
iHn = this.hostnameSlots[iHn+1];
|
||||||
|
} while ( iHn !== 0 );
|
||||||
|
}
|
||||||
|
if ( hostname === '' ) { break; }
|
||||||
|
const pos = hostname.indexOf('.');
|
||||||
|
if ( pos !== -1 ) {
|
||||||
|
hostname = hostname.slice(pos + 1);
|
||||||
|
} else if ( hostname !== '*' ) {
|
||||||
|
hostname = '*';
|
||||||
|
} else {
|
||||||
|
hostname = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
toSelfie() {
|
toSelfie() {
|
||||||
return {
|
return {
|
||||||
hostnameToSlotIdMap: Array.from(this.hostnameToSlotIdMap),
|
hostnameToSlotIdMap: Array.from(this.hostnameToSlotIdMap),
|
||||||
|
@ -53,6 +53,9 @@ window.addEventListener('webextFlavor', function() {
|
|||||||
vAPI.webextFlavor.major < 59;
|
vAPI.webextFlavor.major < 59;
|
||||||
}, { once: true });
|
}, { once: true });
|
||||||
|
|
||||||
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/1553
|
||||||
|
const supportsFloc = document.interestCohort instanceof Function;
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// Intercept and filter web requests.
|
// Intercept and filter web requests.
|
||||||
@ -551,6 +554,9 @@ const onHeadersReceived = function(details) {
|
|||||||
if ( injectCSP(fctxt, pageStore, responseHeaders) === true ) {
|
if ( injectCSP(fctxt, pageStore, responseHeaders) === true ) {
|
||||||
modifiedHeaders = true;
|
modifiedHeaders = true;
|
||||||
}
|
}
|
||||||
|
if ( supportsFloc && foilFloc(fctxt, responseHeaders) ) {
|
||||||
|
modifiedHeaders = true;
|
||||||
|
}
|
||||||
|
|
||||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1376932
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1376932
|
||||||
// Prevent document from being cached by the browser if we modified it,
|
// Prevent document from being cached by the browser if we modified it,
|
||||||
@ -1012,6 +1018,23 @@ const injectCSP = function(fctxt, pageStore, responseHeaders) {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/1553
|
||||||
|
// https://github.com/WICG/floc#opting-out-of-computation
|
||||||
|
|
||||||
|
const foilFloc = function(fctxt, responseHeaders) {
|
||||||
|
const hn = fctxt.getHostname();
|
||||||
|
if ( µBlock.scriptletFilteringEngine.hasScriptlet(hn, 1, 'no-floc') === false ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
responseHeaders.push({
|
||||||
|
name: 'Permissions-Policy',
|
||||||
|
value: 'interest-cohort=()' }
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
// https://github.com/gorhill/uBlock/issues/1163
|
// https://github.com/gorhill/uBlock/issues/1163
|
||||||
// "Block elements by size".
|
// "Block elements by size".
|
||||||
// https://github.com/gorhill/uBlock/issues/1390#issuecomment-187310719
|
// https://github.com/gorhill/uBlock/issues/1390#issuecomment-187310719
|
||||||
|
Loading…
Reference in New Issue
Block a user