mirror of https://github.com/gorhill/uBlock.git
Fix various regressions in latest dev build
Related issues: - https://github.com/uBlockOrigin/uBlock-issues/issues/2404 - https://github.com/uBlockOrigin/uBlock-issues/issues/2400#issuecomment-1346050327
This commit is contained in:
parent
e537748988
commit
58e60d6d96
|
@ -19,7 +19,7 @@
|
|||
Home: https://github.com/gorhill/uBlock
|
||||
*/
|
||||
|
||||
// For background page
|
||||
/* globals browser */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -239,3 +239,20 @@ vAPI.prefetching = (( ) => {
|
|||
})();
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.scriptletsInjector = ((doc, scriptlets) => {
|
||||
let script;
|
||||
try {
|
||||
script = doc.createElement('script');
|
||||
script.appendChild(doc.createTextNode(scriptlets));
|
||||
(doc.head || doc.documentElement).appendChild(script);
|
||||
self.uBO_scriptletsInjected = true;
|
||||
} catch (ex) {
|
||||
}
|
||||
if ( script ) {
|
||||
script.remove();
|
||||
script.textContent = '';
|
||||
}
|
||||
}).toString();
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -1263,6 +1263,15 @@ vAPI.Net = class {
|
|||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
// To be defined by platform-specific code.
|
||||
|
||||
vAPI.scriptletsInjector = (( ) => {
|
||||
self.uBO_scriptletsInjected = true;
|
||||
}).toString();
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus#Browser_compatibility
|
||||
// Firefox for Android does no support browser.contextMenus.
|
||||
|
||||
|
|
|
@ -303,3 +303,23 @@ vAPI.Net = class extends vAPI.Net {
|
|||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.scriptletsInjector = ((doc, scriptlets) => {
|
||||
let script, url;
|
||||
try {
|
||||
const blob = new self.Blob([ scriptlets ], { type: 'text/javascript' });
|
||||
url = self.URL.createObjectURL(blob);
|
||||
script = doc.createElement('script');
|
||||
script.async = false;
|
||||
script.src = url;
|
||||
(doc.head || doc.documentElement).appendChild(script);
|
||||
self.uBO_scriptletsInjected = true;
|
||||
} catch (ex) {
|
||||
}
|
||||
if ( url ) {
|
||||
if ( script ) { script.remove(); }
|
||||
self.URL.revokeObjectURL(url);
|
||||
}
|
||||
}).toString();
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -541,7 +541,7 @@ class ProceduralFilterer {
|
|||
|
||||
styleTokenFromStyle(style) {
|
||||
if ( style === undefined ) { return; }
|
||||
let styleToken = this.styleTokenMap.get(vAPI.hideStyle);
|
||||
let styleToken = this.styleTokenMap.get(style);
|
||||
if ( styleToken !== undefined ) { return styleToken; }
|
||||
styleToken = vAPI.randomToken();
|
||||
this.styleTokenMap.set(style, styleToken);
|
||||
|
|
|
@ -470,15 +470,13 @@ vAPI.injectScriptlet = function(doc, text) {
|
|||
const blob = new self.Blob([ text ], { type: 'text/javascript' });
|
||||
url = self.URL.createObjectURL(blob);
|
||||
script = doc.createElement('script');
|
||||
script.async = false;
|
||||
script.src = url;
|
||||
(doc.head || doc.documentElement || doc).appendChild(script);
|
||||
} catch (ex) {
|
||||
}
|
||||
if ( script ) {
|
||||
script.remove();
|
||||
script.src = '';
|
||||
}
|
||||
if ( url ) {
|
||||
if ( script ) { script.remove(); }
|
||||
self.URL.revokeObjectURL(url);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -88,7 +88,7 @@ const scriptletFilteringEngine = {
|
|||
const contentscriptCode = (( ) => {
|
||||
const parts = [
|
||||
'(',
|
||||
function(hostname, scriptlets) {
|
||||
function(injector, hostname, scriptlets) {
|
||||
const doc = document;
|
||||
if (
|
||||
doc.location === null ||
|
||||
|
@ -97,29 +97,11 @@ const contentscriptCode = (( ) => {
|
|||
) {
|
||||
return;
|
||||
}
|
||||
let script, url;
|
||||
try {
|
||||
const blob = new self.Blob(
|
||||
[ decodeURIComponent(scriptlets) ],
|
||||
{ type: 'text/javascript' }
|
||||
);
|
||||
url = self.URL.createObjectURL(blob);
|
||||
script = doc.createElement('script');
|
||||
script.src = url;
|
||||
(doc.head || doc.documentElement).appendChild(script);
|
||||
self.uBO_scriptletsInjected = true;
|
||||
} catch (ex) {
|
||||
}
|
||||
if ( script ) {
|
||||
script.remove();
|
||||
script.src = '';
|
||||
}
|
||||
if ( url ) {
|
||||
self.URL.revokeObjectURL(url);
|
||||
}
|
||||
injector(doc, decodeURIComponent(scriptlets));
|
||||
if ( typeof self.uBO_scriptletsInjected === 'boolean' ) { return 0; }
|
||||
}.toString(),
|
||||
')(',
|
||||
vAPI.scriptletsInjector, ', ',
|
||||
'"', 'hostname-slot', '", ',
|
||||
'"', 'scriptlets-slot', '"',
|
||||
');',
|
||||
|
@ -130,8 +112,7 @@ const contentscriptCode = (( ) => {
|
|||
scriptletsSlot: parts.indexOf('scriptlets-slot'),
|
||||
assemble: function(hostname, scriptlets) {
|
||||
this.parts[this.hostnameSlot] = hostname;
|
||||
this.parts[this.scriptletsSlot] =
|
||||
encodeURIComponent(scriptlets);
|
||||
this.parts[this.scriptletsSlot] = encodeURIComponent(scriptlets);
|
||||
return this.parts.join('');
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue