2022-09-16 13:56:35 -06:00
|
|
|
/*******************************************************************************
|
|
|
|
|
|
|
|
uBlock Origin - a browser extension to block requests.
|
|
|
|
Copyright (C) 2022-present Raymond Hill
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
|
|
|
|
|
|
Home: https://github.com/gorhill/uBlock
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* jshint esversion:11 */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
import { browser } from './ext.js';
|
2022-09-16 13:56:35 -06:00
|
|
|
import { fetchJSON } from './fetch.js';
|
2022-10-10 10:28:24 -06:00
|
|
|
import { getFilteringModeDetails } from './mode-manager.js';
|
|
|
|
import { getEnabledRulesetsDetails } from './ruleset-manager.js';
|
2022-09-20 06:24:01 -06:00
|
|
|
|
2022-09-27 17:51:38 -06:00
|
|
|
import * as ut from './utils.js';
|
2022-09-16 13:56:35 -06:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
const resourceDetailPromises = new Map();
|
2022-09-16 13:56:35 -06:00
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
function getSpecificDetails() {
|
|
|
|
let promise = resourceDetailPromises.get('specific');
|
|
|
|
if ( promise !== undefined ) { return promise; }
|
|
|
|
promise = fetchJSON('/rulesets/specific-details').then(entries => {
|
2022-09-29 17:51:33 -06:00
|
|
|
const out = new Map();
|
|
|
|
for ( const entry of entries ) {
|
|
|
|
out.set(entry[0], new Map(entry[1]));
|
2022-09-18 07:31:44 -06:00
|
|
|
}
|
|
|
|
return out;
|
2022-09-16 13:56:35 -06:00
|
|
|
});
|
2022-10-15 11:05:20 -06:00
|
|
|
resourceDetailPromises.set('specific', promise);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDeclarativeDetails() {
|
|
|
|
let promise = resourceDetailPromises.get('declarative');
|
|
|
|
if ( promise !== undefined ) { return promise; }
|
|
|
|
promise = fetchJSON('/rulesets/declarative-details').then(
|
|
|
|
entries => new Map(entries)
|
|
|
|
);
|
|
|
|
resourceDetailPromises.set('declarative', promise);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getProceduralDetails() {
|
|
|
|
let promise = resourceDetailPromises.get('procedural');
|
|
|
|
if ( promise !== undefined ) { return promise; }
|
|
|
|
promise = fetchJSON('/rulesets/procedural-details').then(
|
|
|
|
entries => new Map(entries)
|
|
|
|
);
|
|
|
|
resourceDetailPromises.set('procedural', promise);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getScriptletDetails() {
|
|
|
|
let promise = resourceDetailPromises.get('scriptlet');
|
|
|
|
if ( promise !== undefined ) { return promise; }
|
|
|
|
promise = fetchJSON('/rulesets/scriptlet-details').then(
|
|
|
|
entries => new Map(entries)
|
|
|
|
);
|
|
|
|
resourceDetailPromises.set('scriptlet', promise);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getGenericDetails() {
|
|
|
|
let promise = resourceDetailPromises.get('generic');
|
|
|
|
if ( promise !== undefined ) { return promise; }
|
|
|
|
promise = fetchJSON('/rulesets/generic-details').then(
|
|
|
|
entries => new Map(entries)
|
|
|
|
);
|
|
|
|
resourceDetailPromises.set('generic', promise);
|
|
|
|
return promise;
|
2022-09-16 13:56:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2022-10-10 10:28:24 -06:00
|
|
|
// Important: We need to sort the arrays for fast comparison
|
2022-10-15 11:05:20 -06:00
|
|
|
const arrayEq = (a = [], b = [], sort = true) => {
|
2022-10-10 10:28:24 -06:00
|
|
|
const alen = a.length;
|
|
|
|
if ( alen !== b.length ) { return false; }
|
2022-10-15 11:05:20 -06:00
|
|
|
if ( sort ) { a.sort(); b.sort(); }
|
2022-10-10 10:28:24 -06:00
|
|
|
for ( let i = 0; i < alen; i++ ) {
|
|
|
|
if ( a[i] !== b[i] ) { return false; }
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
// The extensions API does not always return exactly what we fed it, so we
|
|
|
|
// need to normalize some entries to be sure we properly detect changes when
|
|
|
|
// comparing registered entries vs. entries to register.
|
|
|
|
|
|
|
|
const normalizeRegisteredContentScripts = registered => {
|
|
|
|
for ( const entry of registered ) {
|
|
|
|
const { js } = entry;
|
|
|
|
for ( let i = 0; i < js.length; i++ ) {
|
|
|
|
const path = js[i];
|
|
|
|
if ( path.startsWith('/') ) { continue; }
|
|
|
|
js[i] = `/${path}`;
|
|
|
|
}
|
2022-09-16 13:56:35 -06:00
|
|
|
}
|
2022-10-15 11:05:20 -06:00
|
|
|
return registered;
|
2022-10-10 10:28:24 -06:00
|
|
|
};
|
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
function registerGeneric(context, genericDetails) {
|
|
|
|
const { before, filteringModeDetails, rulesetsDetails } = context;
|
|
|
|
|
|
|
|
const excludeHostnames = [];
|
|
|
|
const js = [];
|
|
|
|
for ( const details of rulesetsDetails ) {
|
|
|
|
const hostnames = genericDetails.get(details.id);
|
|
|
|
if ( hostnames !== undefined ) {
|
|
|
|
excludeHostnames.push(...hostnames);
|
|
|
|
}
|
[mv3] Add ability to handle entity-based CSS and scriptlet injection filters
This commit adds the ability to inject entity-based plain CSS
filters and also a set of the most commonly used entity-based
scriptlet injection filters.
Since the scripting API is not compatible with entity patterns,
the entity-related content scripts are injected in all documents
and the entity-matching is done by the content script themselves.
Given this, entity-based content scripts are enabled only when
working in the Complete filtering mode, there won't be any
entity-based filters injected in lower modes.
Also, since there is no way to reasonably have access to the
Public Suffix List in the content scripts, the entity-matching
algorithm is an approximation, though I expect false positives
to be rare (time will tell). In the event of such false
positive, simply falling back to Optimal mode will fix the
issue.
The following issues have been fixed at the same time:
Fixed the no-filtering mode related rules having lower priority
then redirect rules, i.e. redirect rules would still be applied
despite disabling all filtering on a site.
Fixed improper detection of changes to the generic-related CSS
content script, potentially causing undue delays when for example
trying to access the popup panel while working in Complete mode.
The scripting MV3 can be quite slow when registering/updating
large content scripts, so uBOL does its best to call the API only
if really needed, but there had been a regression in the recent
builds preventing uBO from properly detecting unchanged content
script parameters.
2022-10-20 13:48:06 -06:00
|
|
|
if ( details.css.generic instanceof Object === false ) { continue; }
|
2022-10-15 11:05:20 -06:00
|
|
|
if ( details.css.generic.count === 0 ) { continue; }
|
[mv3] Add ability to handle entity-based CSS and scriptlet injection filters
This commit adds the ability to inject entity-based plain CSS
filters and also a set of the most commonly used entity-based
scriptlet injection filters.
Since the scripting API is not compatible with entity patterns,
the entity-related content scripts are injected in all documents
and the entity-matching is done by the content script themselves.
Given this, entity-based content scripts are enabled only when
working in the Complete filtering mode, there won't be any
entity-based filters injected in lower modes.
Also, since there is no way to reasonably have access to the
Public Suffix List in the content scripts, the entity-matching
algorithm is an approximation, though I expect false positives
to be rare (time will tell). In the event of such false
positive, simply falling back to Optimal mode will fix the
issue.
The following issues have been fixed at the same time:
Fixed the no-filtering mode related rules having lower priority
then redirect rules, i.e. redirect rules would still be applied
despite disabling all filtering on a site.
Fixed improper detection of changes to the generic-related CSS
content script, potentially causing undue delays when for example
trying to access the popup panel while working in Complete mode.
The scripting MV3 can be quite slow when registering/updating
large content scripts, so uBOL does its best to call the API only
if really needed, but there had been a regression in the recent
builds preventing uBO from properly detecting unchanged content
script parameters.
2022-10-20 13:48:06 -06:00
|
|
|
js.push(`/rulesets/scripting/generic/${details.id}.js`);
|
2022-10-15 11:05:20 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( js.length === 0 ) { return; }
|
|
|
|
|
|
|
|
js.push('/js/scripting/css-generic.js');
|
|
|
|
|
|
|
|
const matches = [];
|
|
|
|
const excludeMatches = [];
|
|
|
|
if ( filteringModeDetails.extendedGeneric.has('all-urls') ) {
|
|
|
|
excludeMatches.push(...ut.matchesFromHostnames(filteringModeDetails.none));
|
|
|
|
excludeMatches.push(...ut.matchesFromHostnames(filteringModeDetails.network));
|
|
|
|
excludeMatches.push(...ut.matchesFromHostnames(filteringModeDetails.extendedSpecific));
|
|
|
|
excludeMatches.push(...ut.matchesFromHostnames(excludeHostnames));
|
|
|
|
matches.push('<all_urls>');
|
|
|
|
} else {
|
|
|
|
matches.push(
|
|
|
|
...ut.matchesFromHostnames(
|
|
|
|
ut.subtractHostnameIters(
|
|
|
|
Array.from(filteringModeDetails.extendedGeneric),
|
|
|
|
excludeHostnames
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( matches.length === 0 ) { return; }
|
|
|
|
|
|
|
|
const registered = before.get('css-generic');
|
|
|
|
before.delete('css-generic'); // Important!
|
|
|
|
|
|
|
|
// register
|
|
|
|
if ( registered === undefined ) {
|
|
|
|
context.toAdd.push({
|
|
|
|
id: 'css-generic',
|
|
|
|
js,
|
|
|
|
matches,
|
|
|
|
excludeMatches,
|
|
|
|
runAt: 'document_idle',
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update
|
|
|
|
const directive = { id: 'css-generic' };
|
|
|
|
if ( arrayEq(registered.js, js, false) === false ) {
|
|
|
|
directive.js = js;
|
|
|
|
}
|
2022-10-10 10:28:24 -06:00
|
|
|
if ( arrayEq(registered.matches, matches) === false ) {
|
|
|
|
directive.matches = matches;
|
2022-09-30 12:55:36 -06:00
|
|
|
}
|
2022-10-10 10:28:24 -06:00
|
|
|
if ( arrayEq(registered.excludeMatches, excludeMatches) === false ) {
|
|
|
|
directive.excludeMatches = excludeMatches;
|
2022-09-24 09:33:04 -06:00
|
|
|
}
|
2022-10-15 11:05:20 -06:00
|
|
|
if ( directive.js || directive.matches || directive.excludeMatches ) {
|
2022-10-10 10:28:24 -06:00
|
|
|
context.toUpdate.push(directive);
|
2022-09-16 13:56:35 -06:00
|
|
|
}
|
2022-10-15 11:05:20 -06:00
|
|
|
}
|
2022-09-19 18:19:55 -06:00
|
|
|
|
2022-09-19 06:55:45 -06:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
function registerProcedural(context, proceduralDetails) {
|
|
|
|
const { before, filteringModeDetails, rulesetsDetails } = context;
|
2022-10-10 10:28:24 -06:00
|
|
|
|
|
|
|
const js = [];
|
2022-11-10 10:46:25 -07:00
|
|
|
const hostnameMatches = new Set();
|
2022-10-10 10:28:24 -06:00
|
|
|
for ( const details of rulesetsDetails ) {
|
2022-10-15 11:05:20 -06:00
|
|
|
if ( details.css.procedural === 0 ) { continue; }
|
[mv3] Add ability to handle entity-based CSS and scriptlet injection filters
This commit adds the ability to inject entity-based plain CSS
filters and also a set of the most commonly used entity-based
scriptlet injection filters.
Since the scripting API is not compatible with entity patterns,
the entity-related content scripts are injected in all documents
and the entity-matching is done by the content script themselves.
Given this, entity-based content scripts are enabled only when
working in the Complete filtering mode, there won't be any
entity-based filters injected in lower modes.
Also, since there is no way to reasonably have access to the
Public Suffix List in the content scripts, the entity-matching
algorithm is an approximation, though I expect false positives
to be rare (time will tell). In the event of such false
positive, simply falling back to Optimal mode will fix the
issue.
The following issues have been fixed at the same time:
Fixed the no-filtering mode related rules having lower priority
then redirect rules, i.e. redirect rules would still be applied
despite disabling all filtering on a site.
Fixed improper detection of changes to the generic-related CSS
content script, potentially causing undue delays when for example
trying to access the popup panel while working in Complete mode.
The scripting MV3 can be quite slow when registering/updating
large content scripts, so uBOL does its best to call the API only
if really needed, but there had been a regression in the recent
builds preventing uBO from properly detecting unchanged content
script parameters.
2022-10-20 13:48:06 -06:00
|
|
|
js.push(`/rulesets/scripting/procedural/${details.id}.js`);
|
2022-10-15 11:05:20 -06:00
|
|
|
if ( proceduralDetails.has(details.id) ) {
|
2022-11-10 10:46:25 -07:00
|
|
|
for ( const hn of proceduralDetails.get(details.id) ) {
|
|
|
|
hostnameMatches.add(hn);
|
|
|
|
}
|
2022-09-30 12:55:36 -06:00
|
|
|
}
|
|
|
|
}
|
2022-09-17 09:22:25 -06:00
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
if ( js.length === 0 ) { return; }
|
|
|
|
|
|
|
|
js.push('/js/scripting/css-procedural.js');
|
|
|
|
|
|
|
|
const {
|
|
|
|
none,
|
|
|
|
network,
|
|
|
|
extendedSpecific,
|
|
|
|
extendedGeneric,
|
|
|
|
} = filteringModeDetails;
|
|
|
|
|
2022-10-10 10:28:24 -06:00
|
|
|
const matches = [];
|
|
|
|
const excludeMatches = [];
|
2022-10-15 11:05:20 -06:00
|
|
|
if ( extendedSpecific.has('all-urls') || extendedGeneric.has('all-urls') ) {
|
|
|
|
excludeMatches.push(...ut.matchesFromHostnames(none));
|
|
|
|
excludeMatches.push(...ut.matchesFromHostnames(network));
|
|
|
|
matches.push(...ut.matchesFromHostnames(hostnameMatches));
|
|
|
|
} else if ( extendedSpecific.size !== 0 || extendedGeneric.size !== 0 ) {
|
|
|
|
matches.push(
|
|
|
|
...ut.matchesFromHostnames(
|
|
|
|
ut.intersectHostnameIters(
|
|
|
|
[ ...extendedSpecific, ...extendedGeneric ],
|
|
|
|
hostnameMatches
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2022-09-27 17:51:38 -06:00
|
|
|
}
|
2022-10-10 10:28:24 -06:00
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
if ( matches.length === 0 ) { return; }
|
|
|
|
|
|
|
|
const registered = before.get('css-procedural');
|
|
|
|
before.delete('css-procedural'); // Important!
|
|
|
|
|
|
|
|
// register
|
|
|
|
if ( registered === undefined ) {
|
|
|
|
context.toAdd.push({
|
|
|
|
id: 'css-procedural',
|
|
|
|
js,
|
2022-10-29 08:02:09 -06:00
|
|
|
allFrames: true,
|
2022-10-15 11:05:20 -06:00
|
|
|
matches,
|
|
|
|
excludeMatches,
|
|
|
|
runAt: 'document_end',
|
|
|
|
});
|
2022-10-10 10:28:24 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
// update
|
|
|
|
const directive = { id: 'css-procedural' };
|
|
|
|
if ( arrayEq(registered.js, js, false) === false ) {
|
|
|
|
directive.js = js;
|
|
|
|
}
|
|
|
|
if ( arrayEq(registered.matches, matches) === false ) {
|
|
|
|
directive.matches = matches;
|
|
|
|
}
|
|
|
|
if ( arrayEq(registered.excludeMatches, excludeMatches) === false ) {
|
|
|
|
directive.excludeMatches = excludeMatches;
|
|
|
|
}
|
|
|
|
if ( directive.js || directive.matches || directive.excludeMatches ) {
|
|
|
|
context.toUpdate.push(directive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
function registerDeclarative(context, declarativeDetails) {
|
|
|
|
const { before, filteringModeDetails, rulesetsDetails } = context;
|
|
|
|
|
|
|
|
const js = [];
|
|
|
|
const hostnameMatches = [];
|
|
|
|
for ( const details of rulesetsDetails ) {
|
|
|
|
if ( details.css.declarative === 0 ) { continue; }
|
[mv3] Add ability to handle entity-based CSS and scriptlet injection filters
This commit adds the ability to inject entity-based plain CSS
filters and also a set of the most commonly used entity-based
scriptlet injection filters.
Since the scripting API is not compatible with entity patterns,
the entity-related content scripts are injected in all documents
and the entity-matching is done by the content script themselves.
Given this, entity-based content scripts are enabled only when
working in the Complete filtering mode, there won't be any
entity-based filters injected in lower modes.
Also, since there is no way to reasonably have access to the
Public Suffix List in the content scripts, the entity-matching
algorithm is an approximation, though I expect false positives
to be rare (time will tell). In the event of such false
positive, simply falling back to Optimal mode will fix the
issue.
The following issues have been fixed at the same time:
Fixed the no-filtering mode related rules having lower priority
then redirect rules, i.e. redirect rules would still be applied
despite disabling all filtering on a site.
Fixed improper detection of changes to the generic-related CSS
content script, potentially causing undue delays when for example
trying to access the popup panel while working in Complete mode.
The scripting MV3 can be quite slow when registering/updating
large content scripts, so uBOL does its best to call the API only
if really needed, but there had been a regression in the recent
builds preventing uBO from properly detecting unchanged content
script parameters.
2022-10-20 13:48:06 -06:00
|
|
|
js.push(`/rulesets/scripting/declarative/${details.id}.js`);
|
2022-10-15 11:05:20 -06:00
|
|
|
if ( declarativeDetails.has(details.id) ) {
|
|
|
|
hostnameMatches.push(...declarativeDetails.get(details.id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( js.length === 0 ) { return; }
|
|
|
|
|
|
|
|
js.push('/js/scripting/css-declarative.js');
|
|
|
|
|
|
|
|
const {
|
|
|
|
none,
|
|
|
|
network,
|
|
|
|
extendedSpecific,
|
|
|
|
extendedGeneric,
|
|
|
|
} = filteringModeDetails;
|
|
|
|
|
|
|
|
const matches = [];
|
|
|
|
const excludeMatches = [];
|
|
|
|
if ( extendedSpecific.has('all-urls') || extendedGeneric.has('all-urls') ) {
|
|
|
|
excludeMatches.push(...ut.matchesFromHostnames(none));
|
|
|
|
excludeMatches.push(...ut.matchesFromHostnames(network));
|
|
|
|
matches.push(...ut.matchesFromHostnames(hostnameMatches));
|
|
|
|
} else if ( extendedSpecific.size !== 0 || extendedGeneric.size !== 0 ) {
|
|
|
|
matches.push(
|
|
|
|
...ut.matchesFromHostnames(
|
|
|
|
ut.intersectHostnameIters(
|
|
|
|
[ ...extendedSpecific, ...extendedGeneric ],
|
|
|
|
hostnameMatches
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( matches.length === 0 ) { return; }
|
|
|
|
|
|
|
|
const registered = before.get('css-declarative');
|
|
|
|
before.delete('css-declarative'); // Important!
|
|
|
|
|
2022-10-10 10:28:24 -06:00
|
|
|
// register
|
|
|
|
if ( registered === undefined ) {
|
|
|
|
context.toAdd.push({
|
2022-10-15 11:05:20 -06:00
|
|
|
id: 'css-declarative',
|
2022-10-10 10:28:24 -06:00
|
|
|
js,
|
2022-10-29 08:02:09 -06:00
|
|
|
allFrames: true,
|
2022-10-10 10:28:24 -06:00
|
|
|
matches,
|
|
|
|
excludeMatches,
|
2022-10-15 11:05:20 -06:00
|
|
|
runAt: 'document_start',
|
2022-10-10 10:28:24 -06:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update
|
2022-10-15 11:05:20 -06:00
|
|
|
const directive = { id: 'css-declarative' };
|
|
|
|
if ( arrayEq(registered.js, js, false) === false ) {
|
2022-10-10 10:28:24 -06:00
|
|
|
directive.js = js;
|
|
|
|
}
|
|
|
|
if ( arrayEq(registered.matches, matches) === false ) {
|
|
|
|
directive.matches = matches;
|
|
|
|
}
|
|
|
|
if ( arrayEq(registered.excludeMatches, excludeMatches) === false ) {
|
|
|
|
directive.excludeMatches = excludeMatches;
|
|
|
|
}
|
|
|
|
if ( directive.js || directive.matches || directive.excludeMatches ) {
|
|
|
|
context.toUpdate.push(directive);
|
|
|
|
}
|
|
|
|
}
|
2022-09-27 17:51:38 -06:00
|
|
|
|
2022-09-16 13:56:35 -06:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
function registerScriptlet(context, scriptletDetails) {
|
|
|
|
const { before, filteringModeDetails, rulesetsDetails } = context;
|
2022-09-16 13:56:35 -06:00
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
const hasBroadHostPermission =
|
|
|
|
filteringModeDetails.extendedSpecific.has('all-urls') ||
|
|
|
|
filteringModeDetails.extendedGeneric.has('all-urls');
|
2022-09-16 13:56:35 -06:00
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
const permissionRevokedMatches = [
|
|
|
|
...ut.matchesFromHostnames(filteringModeDetails.none),
|
|
|
|
...ut.matchesFromHostnames(filteringModeDetails.network),
|
|
|
|
];
|
|
|
|
const permissionGrantedHostnames = [
|
|
|
|
...filteringModeDetails.extendedSpecific,
|
|
|
|
...filteringModeDetails.extendedGeneric,
|
|
|
|
];
|
2022-09-16 13:56:35 -06:00
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
for ( const rulesetId of rulesetsDetails.map(v => v.id) ) {
|
|
|
|
const scriptletList = scriptletDetails.get(rulesetId);
|
|
|
|
if ( scriptletList === undefined ) { continue; }
|
|
|
|
|
|
|
|
for ( const [ token, scriptletHostnames ] of scriptletList ) {
|
|
|
|
const id = `${rulesetId}.${token}`;
|
|
|
|
const registered = before.get(id);
|
|
|
|
|
|
|
|
const matches = [];
|
|
|
|
const excludeMatches = [];
|
|
|
|
if ( hasBroadHostPermission ) {
|
|
|
|
excludeMatches.push(...permissionRevokedMatches);
|
|
|
|
matches.push(...ut.matchesFromHostnames(scriptletHostnames));
|
|
|
|
} else if ( permissionGrantedHostnames.length !== 0 ) {
|
|
|
|
matches.push(
|
|
|
|
...ut.matchesFromHostnames(
|
|
|
|
ut.intersectHostnameIters(
|
|
|
|
permissionGrantedHostnames,
|
|
|
|
scriptletHostnames
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ( matches.length === 0 ) { continue; }
|
|
|
|
|
|
|
|
before.delete(id); // Important!
|
|
|
|
|
|
|
|
// register
|
|
|
|
if ( registered === undefined ) {
|
|
|
|
context.toAdd.push({
|
|
|
|
id,
|
|
|
|
js: [ `/rulesets/scripting/scriptlet/${id}.js` ],
|
2022-10-29 08:02:09 -06:00
|
|
|
allFrames: true,
|
2022-10-15 11:05:20 -06:00
|
|
|
matches,
|
|
|
|
excludeMatches,
|
|
|
|
runAt: 'document_start',
|
|
|
|
world: 'MAIN',
|
|
|
|
});
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update
|
|
|
|
const directive = { id };
|
|
|
|
if ( arrayEq(registered.matches, matches) === false ) {
|
|
|
|
directive.matches = matches;
|
|
|
|
}
|
|
|
|
if ( arrayEq(registered.excludeMatches, excludeMatches) === false ) {
|
|
|
|
directive.excludeMatches = excludeMatches;
|
|
|
|
}
|
|
|
|
if ( directive.matches || directive.excludeMatches ) {
|
|
|
|
context.toUpdate.push(directive);
|
2022-09-20 06:24:01 -06:00
|
|
|
}
|
2022-09-16 13:56:35 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
[mv3] Add ability to handle entity-based CSS and scriptlet injection filters
This commit adds the ability to inject entity-based plain CSS
filters and also a set of the most commonly used entity-based
scriptlet injection filters.
Since the scripting API is not compatible with entity patterns,
the entity-related content scripts are injected in all documents
and the entity-matching is done by the content script themselves.
Given this, entity-based content scripts are enabled only when
working in the Complete filtering mode, there won't be any
entity-based filters injected in lower modes.
Also, since there is no way to reasonably have access to the
Public Suffix List in the content scripts, the entity-matching
algorithm is an approximation, though I expect false positives
to be rare (time will tell). In the event of such false
positive, simply falling back to Optimal mode will fix the
issue.
The following issues have been fixed at the same time:
Fixed the no-filtering mode related rules having lower priority
then redirect rules, i.e. redirect rules would still be applied
despite disabling all filtering on a site.
Fixed improper detection of changes to the generic-related CSS
content script, potentially causing undue delays when for example
trying to access the popup panel while working in Complete mode.
The scripting MV3 can be quite slow when registering/updating
large content scripts, so uBOL does its best to call the API only
if really needed, but there had been a regression in the recent
builds preventing uBO from properly detecting unchanged content
script parameters.
2022-10-20 13:48:06 -06:00
|
|
|
function registerScriptletEntity(context) {
|
|
|
|
const { before, filteringModeDetails, rulesetsDetails } = context;
|
|
|
|
|
|
|
|
const js = [];
|
|
|
|
for ( const details of rulesetsDetails ) {
|
|
|
|
const { scriptlets } = details;
|
|
|
|
if ( scriptlets instanceof Object === false ) { continue; }
|
|
|
|
if ( Array.isArray(scriptlets.entityBasedTokens) === false ) { continue; }
|
|
|
|
if ( scriptlets.entityBasedTokens.length === 0 ) { continue; }
|
|
|
|
for ( const token of scriptlets.entityBasedTokens ) {
|
|
|
|
js.push(`/rulesets/scripting/scriptlet-entity/${details.id}.${token}.js`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( js.length === 0 ) { return; }
|
|
|
|
|
|
|
|
const matches = [];
|
|
|
|
const excludeMatches = [];
|
|
|
|
if ( filteringModeDetails.extendedGeneric.has('all-urls') ) {
|
|
|
|
excludeMatches.push(...ut.matchesFromHostnames(filteringModeDetails.none));
|
|
|
|
excludeMatches.push(...ut.matchesFromHostnames(filteringModeDetails.network));
|
|
|
|
excludeMatches.push(...ut.matchesFromHostnames(filteringModeDetails.extendedSpecific));
|
|
|
|
matches.push('<all_urls>');
|
|
|
|
} else {
|
|
|
|
matches.push(
|
|
|
|
...ut.matchesFromHostnames(filteringModeDetails.extendedGeneric)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( matches.length === 0 ) { return; }
|
|
|
|
|
|
|
|
const registered = before.get('scriptlet.entity');
|
|
|
|
before.delete('scriptlet.entity'); // Important!
|
|
|
|
|
|
|
|
// register
|
|
|
|
if ( registered === undefined ) {
|
|
|
|
context.toAdd.push({
|
|
|
|
id: 'scriptlet.entity',
|
|
|
|
js,
|
2022-10-29 08:02:09 -06:00
|
|
|
allFrames: true,
|
[mv3] Add ability to handle entity-based CSS and scriptlet injection filters
This commit adds the ability to inject entity-based plain CSS
filters and also a set of the most commonly used entity-based
scriptlet injection filters.
Since the scripting API is not compatible with entity patterns,
the entity-related content scripts are injected in all documents
and the entity-matching is done by the content script themselves.
Given this, entity-based content scripts are enabled only when
working in the Complete filtering mode, there won't be any
entity-based filters injected in lower modes.
Also, since there is no way to reasonably have access to the
Public Suffix List in the content scripts, the entity-matching
algorithm is an approximation, though I expect false positives
to be rare (time will tell). In the event of such false
positive, simply falling back to Optimal mode will fix the
issue.
The following issues have been fixed at the same time:
Fixed the no-filtering mode related rules having lower priority
then redirect rules, i.e. redirect rules would still be applied
despite disabling all filtering on a site.
Fixed improper detection of changes to the generic-related CSS
content script, potentially causing undue delays when for example
trying to access the popup panel while working in Complete mode.
The scripting MV3 can be quite slow when registering/updating
large content scripts, so uBOL does its best to call the API only
if really needed, but there had been a regression in the recent
builds preventing uBO from properly detecting unchanged content
script parameters.
2022-10-20 13:48:06 -06:00
|
|
|
matches,
|
|
|
|
excludeMatches,
|
|
|
|
runAt: 'document_start',
|
|
|
|
world: 'MAIN',
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update
|
|
|
|
const directive = { id: 'scriptlet.entity' };
|
|
|
|
if ( arrayEq(registered.js, js, false) === false ) {
|
|
|
|
directive.js = js;
|
|
|
|
}
|
|
|
|
if ( arrayEq(registered.matches, matches) === false ) {
|
|
|
|
directive.matches = matches;
|
|
|
|
}
|
|
|
|
if ( arrayEq(registered.excludeMatches, excludeMatches) === false ) {
|
|
|
|
directive.excludeMatches = excludeMatches;
|
|
|
|
}
|
|
|
|
if ( directive.js || directive.matches || directive.excludeMatches ) {
|
|
|
|
context.toUpdate.push(directive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
function registerSpecific(context, specificDetails) {
|
|
|
|
const { filteringModeDetails } = context;
|
2022-09-16 13:56:35 -06:00
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
let toRegisterMap;
|
2022-10-10 10:28:24 -06:00
|
|
|
if (
|
|
|
|
filteringModeDetails.extendedSpecific.has('all-urls') ||
|
|
|
|
filteringModeDetails.extendedGeneric.has('all-urls')
|
|
|
|
) {
|
2022-10-15 11:05:20 -06:00
|
|
|
toRegisterMap = registerSpecificAll(context, specificDetails);
|
|
|
|
} else {
|
|
|
|
toRegisterMap = registerSpecificSome(context, specificDetails);
|
2022-10-10 10:28:24 -06:00
|
|
|
}
|
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
for ( const [ fname, hostnames ] of toRegisterMap ) {
|
|
|
|
toRegisterableScript(context, fname, hostnames);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function registerSpecificSome(context, specificDetails) {
|
|
|
|
const { filteringModeDetails, rulesetsDetails } = context;
|
|
|
|
const toRegisterMap = new Map();
|
|
|
|
|
2022-10-10 10:28:24 -06:00
|
|
|
const targetHostnames = [
|
|
|
|
...filteringModeDetails.extendedSpecific,
|
|
|
|
...filteringModeDetails.extendedGeneric,
|
|
|
|
];
|
|
|
|
|
2022-09-29 17:51:33 -06:00
|
|
|
const checkMatches = (hostnamesToFidsMap, hn) => {
|
|
|
|
let fids = hostnamesToFidsMap.get(hn);
|
2022-09-19 18:19:55 -06:00
|
|
|
if ( fids === undefined ) { return; }
|
2022-09-20 06:24:01 -06:00
|
|
|
if ( typeof fids === 'number' ) { fids = [ fids ]; }
|
2022-09-19 18:19:55 -06:00
|
|
|
for ( const fid of fids ) {
|
2022-09-27 17:51:38 -06:00
|
|
|
const fname = ut.fnameFromFileId(fid);
|
2022-09-29 17:51:33 -06:00
|
|
|
let existing = toRegisterMap.get(fname);
|
2022-09-18 07:31:44 -06:00
|
|
|
if ( existing ) {
|
2022-09-29 17:51:33 -06:00
|
|
|
if ( existing[0] === '*' ) { continue; }
|
|
|
|
existing.push(hn);
|
2022-09-20 06:24:01 -06:00
|
|
|
} else {
|
2022-09-29 17:51:33 -06:00
|
|
|
toRegisterMap.set(fname, existing = [ hn ]);
|
2022-09-20 06:24:01 -06:00
|
|
|
}
|
2022-09-29 17:51:33 -06:00
|
|
|
if ( hn !== '*' ) { continue; }
|
|
|
|
existing.length = 0;
|
|
|
|
existing.push('*');
|
|
|
|
break;
|
2022-09-20 06:24:01 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-10 10:28:24 -06:00
|
|
|
for ( const rulesetDetails of rulesetsDetails ) {
|
2022-10-15 11:05:20 -06:00
|
|
|
const hostnamesToFidsMap = specificDetails.get(rulesetDetails.id);
|
2022-09-29 17:51:33 -06:00
|
|
|
if ( hostnamesToFidsMap === undefined ) { continue; }
|
2022-10-10 10:28:24 -06:00
|
|
|
for ( let hn of targetHostnames ) {
|
2022-09-27 05:46:24 -06:00
|
|
|
while ( hn ) {
|
2022-09-29 17:51:33 -06:00
|
|
|
checkMatches(hostnamesToFidsMap, hn);
|
2022-09-27 17:51:38 -06:00
|
|
|
hn = ut.toBroaderHostname(hn);
|
2022-09-20 06:24:01 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-27 17:51:38 -06:00
|
|
|
return toRegisterMap;
|
|
|
|
}
|
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
function registerSpecificAll(context, specificDetails) {
|
|
|
|
const { filteringModeDetails, rulesetsDetails } = context;
|
2022-09-27 17:51:38 -06:00
|
|
|
const toRegisterMap = new Map();
|
2022-10-15 11:05:20 -06:00
|
|
|
|
2022-10-10 10:28:24 -06:00
|
|
|
const excludeSet = new Set([
|
|
|
|
...filteringModeDetails.network,
|
|
|
|
...filteringModeDetails.none,
|
|
|
|
]);
|
2022-09-17 06:26:41 -06:00
|
|
|
|
2022-10-10 10:28:24 -06:00
|
|
|
for ( const rulesetDetails of rulesetsDetails ) {
|
2022-10-15 11:05:20 -06:00
|
|
|
const hostnamesToFidsMap = specificDetails.get(rulesetDetails.id);
|
2022-09-29 17:51:33 -06:00
|
|
|
if ( hostnamesToFidsMap === undefined ) { continue; }
|
|
|
|
for ( let [ hn, fids ] of hostnamesToFidsMap ) {
|
2022-10-10 10:28:24 -06:00
|
|
|
if ( excludeSet.has(hn) ) { continue; }
|
|
|
|
if ( ut.isDescendantHostnameOfIter(hn, excludeSet) ) { continue; }
|
2022-09-27 17:51:38 -06:00
|
|
|
if ( typeof fids === 'number' ) { fids = [ fids ]; }
|
|
|
|
for ( const fid of fids ) {
|
|
|
|
const fname = ut.fnameFromFileId(fid);
|
2022-09-29 17:51:33 -06:00
|
|
|
let existing = toRegisterMap.get(fname);
|
2022-09-27 17:51:38 -06:00
|
|
|
if ( existing ) {
|
2022-09-29 17:51:33 -06:00
|
|
|
if ( existing[0] === '*' ) { continue; }
|
|
|
|
existing.push(hn);
|
2022-09-27 17:51:38 -06:00
|
|
|
} else {
|
2022-09-29 17:51:33 -06:00
|
|
|
toRegisterMap.set(fname, existing = [ hn ]);
|
2022-09-27 17:51:38 -06:00
|
|
|
}
|
2022-09-29 17:51:33 -06:00
|
|
|
if ( hn !== '*' ) { continue; }
|
|
|
|
existing.length = 0;
|
|
|
|
existing.push('*');
|
|
|
|
break;
|
2022-09-16 13:56:35 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-27 17:51:38 -06:00
|
|
|
return toRegisterMap;
|
|
|
|
}
|
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
const toRegisterableScript = (context, fname, hostnames) => {
|
|
|
|
if ( context.before.has(fname) ) {
|
|
|
|
return toUpdatableScript(context, fname, hostnames);
|
|
|
|
}
|
|
|
|
const matches = hostnames
|
|
|
|
? ut.matchesFromHostnames(hostnames)
|
|
|
|
: [ '<all_urls>' ];
|
|
|
|
const excludeMatches = matches.length === 1 && matches[0] === '<all_urls>'
|
|
|
|
? ut.matchesFromHostnames(context.filteringModeDetails.none)
|
|
|
|
: [];
|
|
|
|
const directive = {
|
|
|
|
id: fname,
|
|
|
|
allFrames: true,
|
|
|
|
matches,
|
|
|
|
excludeMatches,
|
|
|
|
js: [ `/rulesets/scripting/specific/${fname.slice(-1)}/${fname.slice(0,-1)}.js` ],
|
|
|
|
runAt: 'document_start',
|
|
|
|
};
|
|
|
|
context.toAdd.push(directive);
|
|
|
|
};
|
|
|
|
|
|
|
|
const toUpdatableScript = (context, fname, hostnames) => {
|
|
|
|
const registered = context.before.get(fname);
|
|
|
|
context.before.delete(fname); // Important!
|
|
|
|
const directive = { id: fname };
|
|
|
|
const matches = hostnames
|
|
|
|
? ut.matchesFromHostnames(hostnames)
|
|
|
|
: [ '<all_urls>' ];
|
|
|
|
if ( arrayEq(registered.matches, matches) === false ) {
|
|
|
|
directive.matches = matches;
|
|
|
|
}
|
|
|
|
const excludeMatches = matches.length === 1 && matches[0] === '<all_urls>'
|
|
|
|
? ut.matchesFromHostnames(context.filteringModeDetails.none)
|
|
|
|
: [];
|
|
|
|
if ( arrayEq(registered.excludeMatches, excludeMatches) === false ) {
|
|
|
|
directive.excludeMatches = excludeMatches;
|
|
|
|
}
|
|
|
|
if ( directive.matches || directive.excludeMatches ) {
|
|
|
|
context.toUpdate.push(directive);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-09-27 17:51:38 -06:00
|
|
|
/******************************************************************************/
|
|
|
|
|
[mv3] Add ability to handle entity-based CSS and scriptlet injection filters
This commit adds the ability to inject entity-based plain CSS
filters and also a set of the most commonly used entity-based
scriptlet injection filters.
Since the scripting API is not compatible with entity patterns,
the entity-related content scripts are injected in all documents
and the entity-matching is done by the content script themselves.
Given this, entity-based content scripts are enabled only when
working in the Complete filtering mode, there won't be any
entity-based filters injected in lower modes.
Also, since there is no way to reasonably have access to the
Public Suffix List in the content scripts, the entity-matching
algorithm is an approximation, though I expect false positives
to be rare (time will tell). In the event of such false
positive, simply falling back to Optimal mode will fix the
issue.
The following issues have been fixed at the same time:
Fixed the no-filtering mode related rules having lower priority
then redirect rules, i.e. redirect rules would still be applied
despite disabling all filtering on a site.
Fixed improper detection of changes to the generic-related CSS
content script, potentially causing undue delays when for example
trying to access the popup panel while working in Complete mode.
The scripting MV3 can be quite slow when registering/updating
large content scripts, so uBOL does its best to call the API only
if really needed, but there had been a regression in the recent
builds preventing uBO from properly detecting unchanged content
script parameters.
2022-10-20 13:48:06 -06:00
|
|
|
function registerSpecificEntity(context) {
|
|
|
|
const { before, filteringModeDetails, rulesetsDetails } = context;
|
|
|
|
|
|
|
|
const js = [];
|
|
|
|
for ( const details of rulesetsDetails ) {
|
|
|
|
if ( details.css.specific instanceof Object === false ) { continue; }
|
|
|
|
if ( details.css.specific.entityBased === 0 ) { continue; }
|
|
|
|
js.push(`/rulesets/scripting/specific-entity/${details.id}.js`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( js.length === 0 ) { return; }
|
|
|
|
|
|
|
|
const matches = [];
|
|
|
|
const excludeMatches = [];
|
|
|
|
if ( filteringModeDetails.extendedGeneric.has('all-urls') ) {
|
|
|
|
excludeMatches.push(...ut.matchesFromHostnames(filteringModeDetails.none));
|
|
|
|
excludeMatches.push(...ut.matchesFromHostnames(filteringModeDetails.network));
|
|
|
|
excludeMatches.push(...ut.matchesFromHostnames(filteringModeDetails.extendedSpecific));
|
|
|
|
matches.push('<all_urls>');
|
|
|
|
} else {
|
|
|
|
matches.push(
|
|
|
|
...ut.matchesFromHostnames(filteringModeDetails.extendedGeneric)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( matches.length === 0 ) { return; }
|
|
|
|
|
|
|
|
js.push('/js/scripting/css-specific.entity.js');
|
|
|
|
|
|
|
|
const registered = before.get('css-specific.entity');
|
|
|
|
before.delete('css-specific.entity'); // Important!
|
|
|
|
|
|
|
|
// register
|
|
|
|
if ( registered === undefined ) {
|
|
|
|
context.toAdd.push({
|
|
|
|
id: 'css-specific.entity',
|
|
|
|
js,
|
2022-10-29 08:02:09 -06:00
|
|
|
allFrames: true,
|
[mv3] Add ability to handle entity-based CSS and scriptlet injection filters
This commit adds the ability to inject entity-based plain CSS
filters and also a set of the most commonly used entity-based
scriptlet injection filters.
Since the scripting API is not compatible with entity patterns,
the entity-related content scripts are injected in all documents
and the entity-matching is done by the content script themselves.
Given this, entity-based content scripts are enabled only when
working in the Complete filtering mode, there won't be any
entity-based filters injected in lower modes.
Also, since there is no way to reasonably have access to the
Public Suffix List in the content scripts, the entity-matching
algorithm is an approximation, though I expect false positives
to be rare (time will tell). In the event of such false
positive, simply falling back to Optimal mode will fix the
issue.
The following issues have been fixed at the same time:
Fixed the no-filtering mode related rules having lower priority
then redirect rules, i.e. redirect rules would still be applied
despite disabling all filtering on a site.
Fixed improper detection of changes to the generic-related CSS
content script, potentially causing undue delays when for example
trying to access the popup panel while working in Complete mode.
The scripting MV3 can be quite slow when registering/updating
large content scripts, so uBOL does its best to call the API only
if really needed, but there had been a regression in the recent
builds preventing uBO from properly detecting unchanged content
script parameters.
2022-10-20 13:48:06 -06:00
|
|
|
matches,
|
|
|
|
excludeMatches,
|
|
|
|
runAt: 'document_start',
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update
|
|
|
|
const directive = { id: 'css-specific.entity' };
|
|
|
|
if ( arrayEq(registered.js, js, false) === false ) {
|
|
|
|
directive.js = js;
|
|
|
|
}
|
|
|
|
if ( arrayEq(registered.matches, matches) === false ) {
|
|
|
|
directive.matches = matches;
|
|
|
|
}
|
|
|
|
if ( arrayEq(registered.excludeMatches, excludeMatches) === false ) {
|
|
|
|
directive.excludeMatches = excludeMatches;
|
|
|
|
}
|
|
|
|
if ( directive.js || directive.matches || directive.excludeMatches ) {
|
|
|
|
context.toUpdate.push(directive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2022-09-27 17:51:38 -06:00
|
|
|
async function registerInjectables(origins) {
|
|
|
|
void origins;
|
|
|
|
|
|
|
|
if ( browser.scripting === undefined ) { return false; }
|
|
|
|
|
|
|
|
const [
|
2022-10-10 10:28:24 -06:00
|
|
|
filteringModeDetails,
|
|
|
|
rulesetsDetails,
|
2022-10-15 11:05:20 -06:00
|
|
|
declarativeDetails,
|
|
|
|
proceduralDetails,
|
|
|
|
scriptletDetails,
|
|
|
|
specificDetails,
|
|
|
|
genericDetails,
|
2022-09-27 17:51:38 -06:00
|
|
|
registered,
|
|
|
|
] = await Promise.all([
|
2022-10-10 10:28:24 -06:00
|
|
|
getFilteringModeDetails(),
|
|
|
|
getEnabledRulesetsDetails(),
|
2022-10-15 11:05:20 -06:00
|
|
|
getDeclarativeDetails(),
|
|
|
|
getProceduralDetails(),
|
|
|
|
getScriptletDetails(),
|
|
|
|
getSpecificDetails(),
|
|
|
|
getGenericDetails(),
|
2022-09-27 17:51:38 -06:00
|
|
|
browser.scripting.getRegisteredContentScripts(),
|
2022-10-10 10:28:24 -06:00
|
|
|
]);
|
2022-10-15 11:05:20 -06:00
|
|
|
const before = new Map(
|
|
|
|
normalizeRegisteredContentScripts(registered).map(
|
|
|
|
entry => [ entry.id, entry ]
|
|
|
|
)
|
|
|
|
);
|
2022-10-10 10:28:24 -06:00
|
|
|
const toAdd = [], toUpdate = [], toRemove = [];
|
|
|
|
const promises = [];
|
|
|
|
const context = {
|
|
|
|
filteringModeDetails,
|
2022-10-15 11:05:20 -06:00
|
|
|
rulesetsDetails,
|
2022-10-10 10:28:24 -06:00
|
|
|
before,
|
|
|
|
toAdd,
|
|
|
|
toUpdate,
|
|
|
|
toRemove,
|
|
|
|
};
|
2022-09-17 09:22:25 -06:00
|
|
|
|
2022-10-15 11:05:20 -06:00
|
|
|
registerDeclarative(context, declarativeDetails);
|
|
|
|
registerProcedural(context, proceduralDetails);
|
|
|
|
registerScriptlet(context, scriptletDetails);
|
[mv3] Add ability to handle entity-based CSS and scriptlet injection filters
This commit adds the ability to inject entity-based plain CSS
filters and also a set of the most commonly used entity-based
scriptlet injection filters.
Since the scripting API is not compatible with entity patterns,
the entity-related content scripts are injected in all documents
and the entity-matching is done by the content script themselves.
Given this, entity-based content scripts are enabled only when
working in the Complete filtering mode, there won't be any
entity-based filters injected in lower modes.
Also, since there is no way to reasonably have access to the
Public Suffix List in the content scripts, the entity-matching
algorithm is an approximation, though I expect false positives
to be rare (time will tell). In the event of such false
positive, simply falling back to Optimal mode will fix the
issue.
The following issues have been fixed at the same time:
Fixed the no-filtering mode related rules having lower priority
then redirect rules, i.e. redirect rules would still be applied
despite disabling all filtering on a site.
Fixed improper detection of changes to the generic-related CSS
content script, potentially causing undue delays when for example
trying to access the popup panel while working in Complete mode.
The scripting MV3 can be quite slow when registering/updating
large content scripts, so uBOL does its best to call the API only
if really needed, but there had been a regression in the recent
builds preventing uBO from properly detecting unchanged content
script parameters.
2022-10-20 13:48:06 -06:00
|
|
|
registerScriptletEntity(context);
|
2022-10-15 11:05:20 -06:00
|
|
|
registerSpecific(context, specificDetails);
|
[mv3] Add ability to handle entity-based CSS and scriptlet injection filters
This commit adds the ability to inject entity-based plain CSS
filters and also a set of the most commonly used entity-based
scriptlet injection filters.
Since the scripting API is not compatible with entity patterns,
the entity-related content scripts are injected in all documents
and the entity-matching is done by the content script themselves.
Given this, entity-based content scripts are enabled only when
working in the Complete filtering mode, there won't be any
entity-based filters injected in lower modes.
Also, since there is no way to reasonably have access to the
Public Suffix List in the content scripts, the entity-matching
algorithm is an approximation, though I expect false positives
to be rare (time will tell). In the event of such false
positive, simply falling back to Optimal mode will fix the
issue.
The following issues have been fixed at the same time:
Fixed the no-filtering mode related rules having lower priority
then redirect rules, i.e. redirect rules would still be applied
despite disabling all filtering on a site.
Fixed improper detection of changes to the generic-related CSS
content script, potentially causing undue delays when for example
trying to access the popup panel while working in Complete mode.
The scripting MV3 can be quite slow when registering/updating
large content scripts, so uBOL does its best to call the API only
if really needed, but there had been a regression in the recent
builds preventing uBO from properly detecting unchanged content
script parameters.
2022-10-20 13:48:06 -06:00
|
|
|
registerSpecificEntity(context);
|
2022-10-15 11:05:20 -06:00
|
|
|
registerGeneric(context, genericDetails);
|
2022-09-17 09:22:25 -06:00
|
|
|
|
2022-10-10 10:28:24 -06:00
|
|
|
toRemove.push(...Array.from(before.keys()));
|
2022-09-16 13:56:35 -06:00
|
|
|
|
|
|
|
if ( toRemove.length !== 0 ) {
|
2022-09-17 09:22:25 -06:00
|
|
|
console.info(`Unregistered ${toRemove} content (css/js)`);
|
2022-10-10 10:28:24 -06:00
|
|
|
promises.push(
|
2022-09-29 17:51:33 -06:00
|
|
|
browser.scripting.unregisterContentScripts({ ids: toRemove })
|
|
|
|
.catch(reason => { console.info(reason); })
|
|
|
|
);
|
2022-09-16 13:56:35 -06:00
|
|
|
}
|
|
|
|
if ( toAdd.length !== 0 ) {
|
2022-09-17 09:22:25 -06:00
|
|
|
console.info(`Registered ${toAdd.map(v => v.id)} content (css/js)`);
|
2022-10-10 10:28:24 -06:00
|
|
|
promises.push(
|
2022-09-29 17:51:33 -06:00
|
|
|
browser.scripting.registerContentScripts(toAdd)
|
|
|
|
.catch(reason => { console.info(reason); })
|
|
|
|
);
|
2022-09-17 09:22:25 -06:00
|
|
|
}
|
|
|
|
if ( toUpdate.length !== 0 ) {
|
|
|
|
console.info(`Updated ${toUpdate.map(v => v.id)} content (css/js)`);
|
2022-10-10 10:28:24 -06:00
|
|
|
promises.push(
|
2022-09-29 17:51:33 -06:00
|
|
|
browser.scripting.updateContentScripts(toUpdate)
|
|
|
|
.catch(reason => { console.info(reason); })
|
|
|
|
);
|
2022-09-16 13:56:35 -06:00
|
|
|
}
|
2022-10-10 10:28:24 -06:00
|
|
|
if ( promises.length === 0 ) { return; }
|
2022-09-16 13:56:35 -06:00
|
|
|
|
2022-10-10 10:28:24 -06:00
|
|
|
return Promise.all(promises);
|
2022-09-16 13:56:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
export {
|
2022-09-27 17:51:38 -06:00
|
|
|
registerInjectables
|
2022-09-16 13:56:35 -06:00
|
|
|
};
|