Reputation: 12542
Yes, you've seen this topic before. However, Chrome has closed one of the most common ports to use the unsafeWindow
to use with Contents Script.
var unsafeWindow;
(function() {
var div = document.createElement("div");
div.setAttribute("onclick", "return window");
unsafeWindow = div.onclick();
})();
Now div.onclick
returns null.
My question is: is there another way to access the unsafeWindow
via Contents Script, currently? For example, I would like to access the jQuery used by the page itself.
unsafeWindow.jQuery().jquery; // <- 1.9.0
Upvotes: 3
Views: 1647
Reputation: 4026
Well, I have a draft of decision for you. Maybe this is what you need?
Injected.js works inside original window scope, contentscript.js works inside its isolated window scope. The problem is that you don't have unsafeWindow variable, but I think you can wrap your code inside some function with this variable.
*manifest.json
"web_accessible_resources": ["injected.js"],
"content_scripts": [{
"matches": ["*://*/*"],
"js": ["js/content.js"]
}],
...
contentscript.js
var internalScript = document.createElement("script");
internalScript.src = chrome.runtime.getURL("injected.js");
document.body.appendChild(internalScript);
injected.js
console.log(window);
console.log(window.$);
Upvotes: 1