R
R
Roman Andreevich2019-11-05 12:29:31
JavaScript
Roman Andreevich, 2019-11-05 12:29:31

How to execute code in all tabs at the same time?

Colleagues who wrote or write extensions, share your opinion, is it possible to work with several tabs at the same time? Those. execute code on a website page.
I’m reading the documentation and I can’t fully understand, can I work at the moment only with the active tab or with all? Has anyone asked this question?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Somewhere Intech, 2019-11-06
@john36allTa

Pass an empty options object to the chrome.tabs.query function and a callback function where an array of Tab objects will be passed . Next, in the same function, describe chrome.tabs.executeScript with Tab.id. The tab state and other properties will also be passed in the Tab object.

chrome.tabs.query({}, function(tabs){
  for (const tab of tabs){
    chrome.tabs.executeScript(tab.id, {
      // указываете параметры скрипта
    });
  }
});

You can also hang a listener on event chrome.tabs.onCreated for example, or another more suitable one.
PS in the manifest, just specify the permission for tabs and the desired
url mask .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question