New issue
Advanced search Search tips

Issue 841429 link

Starred by 2 users

Issue metadata

Status: Assigned
Owner:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux
Pri: 2
Type: Bug



Sign in to add a comment

Extension devtools inspectedWindow eval call fails on similar frame src urls

Reported by drol...@yahoo.com, May 9 2018

Issue description

UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36

Steps to reproduce the problem:
1. Visit a web page containing two frames. Both frames should have same src base url but end with different #fragments at end. I used www.frames.com which contains iframes with sources "https://www.google.com/afs/ads/i/iframe.html#slave-2-1" and "https://www.google.com/afs/ads/i/iframe.html#slave-1-1". This page is the basis for the following steps. 
2. From devtools extension context, call  chrome.devtools.inspectedWindow.eval("null",{frameURL: "https://www.google.com/afs/ads/i/iframe.html#slave-2-1"},()=>console.log(chrome.runtime.lastError));
3. The call will fail with an error that the object (page) is not found. It seems that the eval code does not like the fragment at the end of the url.
4. Now call eval with the url minus the fragment, ie chrome.devtools.inspectedWindow.eval("null",{frameURL:"https://www.google.com/afs/ads/i/iframe.html"});
5. This call works (a frame is found) but the frame found is not deterministic. Both sub frames match the same base url (without fragment). The eval will execute in one of these two sub frames, but the developer cannot control which one. And the one that is not reached with the call is unreachable (there is no way to differentiate the two frames when calling eval because they have the same src url with fragments removed)

What is the expected behavior?
chrome.devtools.inspectedWindow.eval should allow the developer to eval code in a frame as specified in the documentation. As is, in a page with a group of frames with similar urls, only one frame is reachable, and for the extension developer, the identity of reachable frame is not deterministic.

What went wrong?
The eval api frameURL matching works only on a frame src url with any #fragment removed. If this is the way it should work, it would be good to document.

More importantly, the approach of matching frames on src url doesn't work reliably. In a web page, if multiple frames' sources differ only by their fragments, only one of the frames is reachable (as demonstrated above) via the eval method. Also, multiple frames with the exact same source url can coexist on a page, resulting in the same problem.

I'm developing a devtools elements side panel that reacts to selected node changes. On a change, my code tries to find the selected node by calling the devtools inspectedWindow eval method with code "$0 === null" for each of the window's frames until the node is found. As is, I often can't find the frame containing the node.

I suggest that the eval api method could work reliably using frameId rather than frameURL for frame matching. Perhaps a frameId property could be added to the eval options object and used for matching if specified? But of course I don't understand the internal workings of the system.

Did this work before? N/A 

Chrome version: 66.0.3359.139  Channel: stable
OS Version: 16.04
Flash Version:
 
Labels: Needs-Triage-M66

Comment 2 by alph@chromium.org, May 10 2018

Owner: dgozman@chromium.org
Status: Assigned (was: Unconfirmed)
Here's a stackoverflow question I submitted on this (and a related) issue. Hoping to figure this out somehow.

https://stackoverflow.com/questions/52121654/in-chrome-devtools-extension-how-to-retrieve-selected-node-data-for-extension-e

Sign in to add a comment