Skip to content

Commit 520f81f

Browse files
committed
[mv3] Fix injection of scriptlets into embedded contexts
1 parent 24756e8 commit 520f81f

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

platform/mv3/chromium/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"128": "img/icon_128.png"
2626
},
2727
"manifest_version": 3,
28-
"minimum_chrome_version": "118.0",
28+
"minimum_chrome_version": "119.0",
2929
"name": "__MSG_extName__",
3030
"options_page": "dashboard.html",
3131
"optional_host_permissions": [

platform/mv3/extension/js/scripting-manager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ function registerScriptlet(context, scriptletDetails) {
473473
// `MAIN` world not yet supported in Firefox
474474
if ( isGecko === false ) {
475475
directive.world = 'MAIN';
476+
directive.matchOriginAsFallback = true;
476477
}
477478

478479
// register

platform/mv3/scriptlets/scriptlet.template.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
2121
*/
2222

23-
/* jshint esversion:11 */
23+
/* eslint-disable indent */
2424
/* global cloneInto */
2525

26-
'use strict';
27-
2826
// ruleset: $rulesetId$
2927

3028
/******************************************************************************/
@@ -40,7 +38,7 @@
4038
// Start of code to inject
4139
const uBOL_$scriptletName$ = function() {
4240

43-
const scriptletGlobals = {}; // jshint ignore: line
41+
const scriptletGlobals = {}; // eslint-disable-line
4442

4543
const argsList = self.$argsList$;
4644

@@ -57,7 +55,19 @@ function $scriptletName$(){}
5755
/******************************************************************************/
5856

5957
const hnParts = [];
60-
try { hnParts.push(...document.location.hostname.split('.')); }
58+
try {
59+
let origin = document.location.origin;
60+
if ( origin === 'null' ) {
61+
const origins = document.location.ancestorOrigins;
62+
for ( let i = 0; i < origins.length; i++ ) {
63+
origin = origins[i];
64+
if ( origin !== 'null' ) { break; }
65+
}
66+
}
67+
const pos = origin.lastIndexOf('://');
68+
if ( pos === -1 ) { return; }
69+
hnParts.push(...origin.slice(pos+3).split('.'));
70+
}
6171
catch(ex) { }
6272
const hnpartslen = hnParts.length;
6373
if ( hnpartslen === 0 ) { return; }

0 commit comments

Comments
 (0)