How to get frame by id in Chrome?

I am using onBeforeRequest

chrome.webRequest.onBeforeRequest.addListener(function(object details) {...}); 

Items are returned

frameId (integer)

So, I have a frame id, how can I get the elemental from this id and access src , parentId ...?

+4
source share
1 answer

I assume this is for your background page. You probably don't care about the actual tab, but rather want to associate the header information with this tabId. To do this, follow these steps: 1) create a tab container: "tabs = {}" 2) save the data in this container: "tabs [details.id] .details.push (details);"

It will look something like this:

 tabs = {}; init=function(){ ... chrome.webRequest.onBeforeRedirect.addListener(beforeRedirect, requestFilter, extraInfo); ... } beforeRedirect = function(details){ ... tabs[details.id].details.push(details); ... } 

You also have the ability chrome.tabs.query to connect to the actual tab. If all you need is to save the header information, you probably won't want to use this:

 chrome.tabs.query({active:true, windowId: chrome.windows.WINDOW_ID_CURRENT}, function(tab){ var currentTab = tab[0]; ... 
0
source

Source: https://habr.com/ru/post/1437659/


All Articles