File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -34,11 +34,20 @@ function injectScript() {
34
34
35
35
// DANGER: DO NOT USE GLOBALS HERE WITHOUT `window` OBJECT!! FIREFOX BUG WITH GLOBALS.
36
36
const injectorCode = `
37
- const nScript = document.createElement('script');
38
- nScript.innerHTML = ${ JSON . stringify ( mainCode ) } ;
39
- document.documentElement.append(nScript);
40
- nScript.remove();
41
- ` ;
37
+ // WORKAROUND: TypeError: Failed to set the 'innerHTML' property on 'Element': This document requires 'TrustedHTML' assignment.
38
+ if (window.trustedTypes && !trustedTypes.defaultPolicy) {
39
+ const passThroughFn = (x) => x;
40
+ trustedTypes.createPolicy('default', {
41
+ createHTML: passThroughFn,
42
+ createScriptURL: passThroughFn,
43
+ createScript: passThroughFn,
44
+ });
45
+ }
46
+ const nScript = document.createElement('script');
47
+ nScript.innerHTML = ${ JSON . stringify ( mainCode ) } ;
48
+ document.documentElement.append(nScript);
49
+ nScript.remove();
50
+ ` ;
42
51
43
52
const nInjector = document . createElement ( 'injector' ) ;
44
53
nInjector . setAttribute ( 'onclick' , injectorCode ) ;
You can’t perform that action at this time.
0 commit comments