Original Chrome parent iframe undefined

I have this script for Gmail. It works inside an canvas_frameiframe.
I want to get the handle of the parent document using parent.document. But on Chrome, it tells me that it is undefined. Works fine in Firefox, but explodes in Chrome.
So how exactly do I get the handle of the parent document, from inside the iframe, in Chrome.
Chrome ver: 11.0.686.3

Here's the code that doesn't work:

function init() {
    try {
        if(parent == null) {
            console.log(typeof parent);
            window.setTimeout(init, 200);
            return;
        }
        // SOME MORE STUFF
    } catch(e) { console.log(e) }
}

This part simply displays undefinedendlessly in the log window.
Here a script test is run that gives the same result. He displays undefined, and then cQendlessly.

// ==UserScript==
// @name           TEST SCRIPT FOR CHROME
// @version        1.0
// @namespace      1nfected
// @description    TEST
// @include        http://mail.google.com/*
// @include        https://mail.google.com/*
// ==/UserScript==

(function() {
if(document.documentElement.className != 'cQ') {
    console.log('not our frame');
    return;
}
function init() {
    if(window.parent == null) {
        console.log(typeof window.parent);
        console.log(document.documentElement.className);
        window.setTimeout(init, 1000);
        return;
    }
    console.log('Found the parent');
}
init();
})();
+3
source share
2 answers

, , Google Chrome - window.parent.
, script -.

0

UserScripts Chrome , iframes.

, -? :

var frame = document.getElementById('canvas_frame');
if (frame) {
  var dom = frame.contentDocument;
}

Chrome Extensions, Script Script.

+4

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


All Articles