Chrome-BigConsole
Chrome-BigConsole copied to clipboard
Allow running code in child frames
Starting in Chrome 38, it is possible to execute code in child frames using the options parameter of chrome.devtools.inspectedWindow.eval()
to specify a target frame by its URL.
Getting target frame URLs, and keeping the list updated when those URLs change (by adding/removing frames from the DOM or by changing a frame's location) is actually a somewhat complicated problem. Options are:
-
Insert a script into every frame that communicates with the Dev Tools panel on window load and popstate (when
location.href
changes). This is probably the best option. - Use the
webNavigation.getAllFrames()
method to get all frames in the current tab. However, this makes it complicated to track when the frame's location changes (e.g. if the user clicks a link in the frame). - Target frame URLs can be retrieved by querying for frames (e.g.
document.querySelectorAll('iframe')
from the parent) and accessing the.src
property of each frame. However, the same hoops have to be jumped through to monitor changes as in the second option. - For same-domain, same-protocol frames, the
location.href
of each window inwindow.frames
identifies the URL. However, the same hoops have to be jumped through to monitor changes as in the second option.
This issue is a request on behalf of a user who submitted feedback on the Chrome Web Store to add a new feature to BigConsole to choose a target frame where code should be executed. A new dropdown would need to be added to the code pane listing the available frames, populated using one of the methods above.