surya
surya

Reputation: 123

chrome.devtools.inspectedWindow.eval to inspect element in Iframe (iframe without Iframe URL)

In my extension I am highlighting the node that I have XPATH for. the code below works if I have Iframe with URL hello.com

var script = "var nodes = document.evaluate(\"" + issue.xpath + "\", document, null, XPathResult.ANY_TYPE, null);" +
                "var node = nodes.iterateNext();" +
                "if(node){" +
                "inspect(node);" +
                "}"
            chrome.devtools.inspectedWindow.eval(script, {
                frameURL:
            });

But it does not work for the Iframw WITH OUT url

<html>

<head>
</head>

<body>
    <h2>Main Page</h2>
    <iframe id="Iframe" title="my Iframe">
        <html>

        <head>
        </head>

        <body>
            <h2>Iframe</h2>

        </body>

        </html>
    </iframe>
</body>

</html>

What would be the URL in this case?

Upvotes: 1

Views: 1137

Answers (1)

woxxom
woxxom

Reputation: 73846

Chromium source code (ExtensionServer.js) shows that inspectedWindow.eval() can't do that:

var frame = options.frameURL ? resolveURLToFrame(options.frameURL) : WebInspector.targetManager.mainTarget().resourceTreeModel.mainFrame;
if (!frame) {
    if (options.frameURL)
        console.warn("evaluate: there is no frame with URL " + options.frameURL);
    else
        console.warn("evaluate: the main frame is not yet available");
    return this._status.E_NOTFOUND(options.frameURL || "<top>");
}

Submit a feature request on bugs.chromium.org.

I'm not aware of a workaround, but have a look at advanced devtools extensions, e.g. famous and others.

Upvotes: 1

Related Questions