Google Chrome UserScript - Working with other windows and tied hands

I have a small problem with UserScripts in Google Chrome, more precisely, in order to get into the window of the iframe object. It’s very convenient using the Google Chrome console, which is very impossible with UserScript or so it seems. Honestly, it looks like it was on purpose, as if there was a reason why I was not allowed to access other window objects.

document.body.innerHTML += "<iframe name='iframe'></iframe>";
console.log(top.frames.iframe);
console.log(window.frames.iframe);
console.log(unsafeWindow.frames.iframe);
console.log(document.getElementsByName('iframe')[0].contentWindow);
console.log(document.getElementsByName('iframe')[0].contentDocument.defaultView);

->

chrome-extension://eelclpmekkanegjojjmaldeddncficoj/script.js:14 undefined
chrome-extension://eelclpmekkanegjojjmaldeddncficoj/script.js:15 undefined
chrome-extension://eelclpmekkanegjojjmaldeddncficoj/script.js:16 undefined
chrome-extension://eelclpmekkanegjojjmaldeddncficoj/script.js:17 undefined
chrome-extension://eelclpmekkanegjojjmaldeddncficoj/script.js:18 undefined

May I ask what is the Chrome issue? I really don't understand why the user interface has less javascript access than a regular script, what are the consequences? By the way, yes, iframe is in the same domain and protocol. :(

+3
1

UnsafeWindow Chrome, TamperMonkey, , .

contentWindow.document Chrome. contentDocument .

, XMLHttpRequest . . Chrome - , /, - . , .

document.getElementsByName('iframe') [0].contentWindow, , , iframe. -, iframe "iframe", .

innerHTML, appendChild() iframe document.body. , document.getElementsByName, document.body.getElementsByName.

greasemonkey firefox, Chrome . , . http://wiki.greasespot.net/Location_hack. Javascript ;) , , iframes userscripts. script Greasemonkey, 6 , -, iframe, , undefined, javascript. , .js script , , , undefined. 6 , .js script . , , , . iframe, ...

+2

Source: https://habr.com/ru/post/1772346/


All Articles