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
|
Home: https://github.com/gorhill/uBlock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// For background page
|
/* globals browser */
|
||||||
|
|
||||||
'use strict';
|
'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
|
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus#Browser_compatibility
|
||||||
// Firefox for Android does no support browser.contextMenus.
|
// 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) {
|
styleTokenFromStyle(style) {
|
||||||
if ( style === undefined ) { return; }
|
if ( style === undefined ) { return; }
|
||||||
let styleToken = this.styleTokenMap.get(vAPI.hideStyle);
|
let styleToken = this.styleTokenMap.get(style);
|
||||||
if ( styleToken !== undefined ) { return styleToken; }
|
if ( styleToken !== undefined ) { return styleToken; }
|
||||||
styleToken = vAPI.randomToken();
|
styleToken = vAPI.randomToken();
|
||||||
this.styleTokenMap.set(style, styleToken);
|
this.styleTokenMap.set(style, styleToken);
|
||||||
|
|
|
@ -470,15 +470,13 @@ vAPI.injectScriptlet = function(doc, text) {
|
||||||
const blob = new self.Blob([ text ], { type: 'text/javascript' });
|
const blob = new self.Blob([ text ], { type: 'text/javascript' });
|
||||||
url = self.URL.createObjectURL(blob);
|
url = self.URL.createObjectURL(blob);
|
||||||
script = doc.createElement('script');
|
script = doc.createElement('script');
|
||||||
|
script.async = false;
|
||||||
script.src = url;
|
script.src = url;
|
||||||
(doc.head || doc.documentElement || doc).appendChild(script);
|
(doc.head || doc.documentElement || doc).appendChild(script);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
}
|
}
|
||||||
if ( script ) {
|
|
||||||
script.remove();
|
|
||||||
script.src = '';
|
|
||||||
}
|
|
||||||
if ( url ) {
|
if ( url ) {
|
||||||
|
if ( script ) { script.remove(); }
|
||||||
self.URL.revokeObjectURL(url);
|
self.URL.revokeObjectURL(url);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -88,7 +88,7 @@ const scriptletFilteringEngine = {
|
||||||
const contentscriptCode = (( ) => {
|
const contentscriptCode = (( ) => {
|
||||||
const parts = [
|
const parts = [
|
||||||
'(',
|
'(',
|
||||||
function(hostname, scriptlets) {
|
function(injector, hostname, scriptlets) {
|
||||||
const doc = document;
|
const doc = document;
|
||||||
if (
|
if (
|
||||||
doc.location === null ||
|
doc.location === null ||
|
||||||
|
@ -97,29 +97,11 @@ const contentscriptCode = (( ) => {
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let script, url;
|
injector(doc, decodeURIComponent(scriptlets));
|
||||||
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);
|
|
||||||
}
|
|
||||||
if ( typeof self.uBO_scriptletsInjected === 'boolean' ) { return 0; }
|
if ( typeof self.uBO_scriptletsInjected === 'boolean' ) { return 0; }
|
||||||
}.toString(),
|
}.toString(),
|
||||||
')(',
|
')(',
|
||||||
|
vAPI.scriptletsInjector, ', ',
|
||||||
'"', 'hostname-slot', '", ',
|
'"', 'hostname-slot', '", ',
|
||||||
'"', 'scriptlets-slot', '"',
|
'"', 'scriptlets-slot', '"',
|
||||||
');',
|
');',
|
||||||
|
@ -130,8 +112,7 @@ const contentscriptCode = (( ) => {
|
||||||
scriptletsSlot: parts.indexOf('scriptlets-slot'),
|
scriptletsSlot: parts.indexOf('scriptlets-slot'),
|
||||||
assemble: function(hostname, scriptlets) {
|
assemble: function(hostname, scriptlets) {
|
||||||
this.parts[this.hostnameSlot] = hostname;
|
this.parts[this.hostnameSlot] = hostname;
|
||||||
this.parts[this.scriptletsSlot] =
|
this.parts[this.scriptletsSlot] = encodeURIComponent(scriptlets);
|
||||||
encodeURIComponent(scriptlets);
|
|
||||||
return this.parts.join('');
|
return this.parts.join('');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue