Yes, including the script on the page is executed in an isolated context from the runtime script page.
However, you can work around the problem of isolated worlds by clicking inline script on the runtime context through the script tag added to the html document. After that, the inline script can create a custom event.
An included script in an isolated context can listen to this event and respond accordingly.
Thus, the code in your included script will look something like this:
// inject code into "the other side" to talk back to this side; var scr = document.createElement('script'); //appending text to a function to convert it src to string only works in Chrome scr.textContent = '(' + function () { var check = [do your custom code here]; var event = document.createEvent("CustomEvent"); event.initCustomEvent("MyCustomEvent", true, true, {"passback":check}); window.dispatchEvent(event); } + ')();' //cram that sucker in (document.head || document.documentElement).appendChild(scr); //and then hide the evidence as much as possible. scr.parentNode.removeChild(scr); //now listen for the message window.addEventListener("MyCustomEvent", function (e) { var check = e.detail.passback; // [do what you need to here]. });
PatAtCP
source share