Skip to content

Commit

Permalink
[mv3] Remove obsolete Firefox-only workaround in scriptlet template
Browse files Browse the repository at this point in the history
Related bugzilla issue:
https://bugzilla.mozilla.org/show_bug.cgi?id=1736575

The issue was fixed months ago.

The removed code block is causing uBOL to be flagged as "including
remotely hosted code".

To be clear, the removed obsolete code block was not related to
executing remote code. The referenced code was in the file itself,
not remote, and this was a workaround for when Firefox was not
supporting injecting script in the `MAIN` world.

The issue was fixed months ago in Firefox, so there is no point for
the workaround.
  • Loading branch information
gorhill committed Nov 13, 2024
1 parent d325dcd commit 2e745f9
Showing 1 changed file with 1 addition and 39 deletions.
40 changes: 1 addition & 39 deletions platform/mv3/scriptlets/scriptlet.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

/* eslint-disable indent */
/* global cloneInto */

// ruleset: $rulesetId$

Expand Down Expand Up @@ -136,44 +135,7 @@ argsList.length = 0;

/******************************************************************************/

// Inject code

// https://bugzilla.mozilla.org/show_bug.cgi?id=1736575
// 'MAIN' world not yet supported in Firefox, so we inject the code into
// 'MAIN' ourself when environment in Firefox.

const targetWorld = '$world$';

// Not Firefox
if ( typeof wrappedJSObject !== 'object' || targetWorld === 'ISOLATED' ) {
return uBOL_$scriptletName$();
}

// Firefox
{
const page = self.wrappedJSObject;
let script, url;
try {
page.uBOL_$scriptletName$ = cloneInto([
[ '(', uBOL_$scriptletName$.toString(), ')();' ],
{ type: 'text/javascript; charset=utf-8' },
], self);
const blob = new page.Blob(...page.uBOL_$scriptletName$);
url = page.URL.createObjectURL(blob);
const doc = page.document;
script = doc.createElement('script');
script.async = false;
script.src = url;
(doc.head || doc.documentElement || doc).append(script);
} catch (ex) {
console.error(ex);
}
if ( url ) {
if ( script ) { script.remove(); }
page.URL.revokeObjectURL(url);
}
delete page.uBOL_$scriptletName$;
}
uBOL_$scriptletName$();

/******************************************************************************/

Expand Down

0 comments on commit 2e745f9

Please sign in to comment.