I want my Chrome extension to rerun a contentscript for all open tabs prior to viewing the popup window to gather the most recent data about each webpage (it sends a message to the background page). My problem is that in order to get full access to each iframe, I need to set allframes to true. This means that prior to showing the popup window, I need to wait until I have received a message from each frame.
My problem is that I am not sure how to determine how many frames there are. One approach I looked at would be to detect the frame count from within the contentscript, but there is an open bug which indicates that you can’t request that right now. Another is to just wait for a number of responses equivalent to what I got when I first navigated to the page, but it is possible that due to AJAX calls the number of frames increased since then. Finally, I was hoping that the response to chrome.extension.SendRequest would include such information but it does not.
Your help is appreciated.
I suggest that you always run the content script from the manifest, so that the content script will run every time a new frame loads. Then, have the content script open a port to the extension, so that every open frame has a port to the background. Then it’s up to the background page to keep track of all the open ports for each tab, and send messages to the desired ports.