Is there a way to use chrome.tabs.executeScript to get all frameId's in a tab?
I tried executeScript() then have the code send a message to background which would send it back to the content with the frameId, however it's async. And, executeScript() needs sync return.
Yes, you can get a list of frameId's for a tab using
chrome.tabs.executeScript()(MDN).As it sounds like you have determined, it is a bit convoluted to do so. You could usechrome.tabs.executeScript()with the optionallFrames:trueto inject a content script into all frames in the tab. Your content script would then need to send a message back to the background context usingchrome.runtime.sendMessage()(MDN). TheframeIdwill then be available for each frame as a property of the Object passed as the second argument, thesender(MDN), to yourchrome.runtime.onMessage(MDN) listener. You will need to accumulate the list yourself.A much better way: use
chrome.webNavigation.getAllFrames()(MDN)As wOxxOm mentioned in a comment, It would be much easier to get it from
chrome.webNavigation.getAllFrames()(MDN).There is no way to obtain a list of frameId's for a tab using a synchronous interface. As wOxxOm also mentioned, the only way to do it is to obtain the information prior to you needing it. If you need it for a call to
chrome.tabs.executeScript(), then you can make the call tochrome.tabs.executeScript()from the callback forchrome.webNavigation.getAllFrames().