You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to get a reference to the true global scope.
window.load , etc, etc all provide a reference to window that is limited to content scripts.
I see that in the content script that you are using Function to immediately run the script.
What if there was an option to load the content into a script tag. Similar to what you are doing with css (and style tags).
in this way the script should load as if it was a local script and thus have global scope, etc.
maybe there could be a new declaration of
//@mode=X
X===1 means to behave as proposed below @mode missing or undefined, etc means to behave as you already have it (using Function(scriptContents)())
chrome.runtime.onMessage.addListener(({scriptType, scriptContents})=>{if(scriptType==="js"){constscriptEl=document.createElement('script');scriptEl.type='text/javscript';scriptEl.appendChild(document.createTextNode(scriptContents));scriptEl.setAttribute("data-witchcraft","");// to make it easy finding the element if we want todocument.body.appendChild(scriptEl);}elseif(scriptType==="css"){conststyle=document.createElement('style');style.type='text/css';style.appendChild(document.createTextNode(scriptContents));style.setAttribute("data-witchcraft","");// to make it easy finding the element if we want todocument.head.appendChild(style);}});
The text was updated successfully, but these errors were encountered:
Note that mode 0 and 1 are the meaningful ones. The user can do 2 and 3 simply by adding event listener wrappers on their own scripts in combination with mode 1.
I would like to get a reference to the true global scope.
window.load
, etc, etc all provide a reference to window that is limited to content scripts.I see that in the content script that you are using
Function
to immediately run the script.What if there was an option to load the content into a
script
tag. Similar to what you are doing with css (andstyle
tags).in this way the script should load as if it was a local script and thus have global scope, etc.
maybe there could be a new declaration of
//@mode=X
X===1 means to behave as proposed below
@mode
missing or undefined, etc means to behave as you already have it (usingFunction(scriptContents)()
)The text was updated successfully, but these errors were encountered: