Chrome-BigConsole icon indicating copy to clipboard operation
Chrome-BigConsole copied to clipboard

Allow running code in child frames

Open IceCreamYou opened this issue 9 years ago • 0 comments

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:

  1. 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.
  2. 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).
  3. 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.
  4. For same-domain, same-protocol frames, the location.href of each window in window.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.

IceCreamYou avatar Dec 20 '15 06:12 IceCreamYou