Can Chrome extension content script access all tabs?

3k views Asked by At

Basically, I want to get all the opened tabs of the browser window, from within a tab, more specifically, in content script.

I tried chrome.tabs.query, it works in background script, but doesn't work in content script.

So my questions are:

  1. Is there a way to do such work? Maybe an API that I wasn't aware of?

  2. Or, can I dispatch an event from content script, then capture the event in background script, and vice versa?

  3. Or, is it just impossible?

1

There are 1 answers

1
Erich Kitzmueller On BEST ANSWER

According to https://developer.chrome.com/extensions/content_scripts , a content script cannot access chrome.* APIs, except a few allowed ones but chrome.tabs is not among them

Exchanging messages with the parent script is possible, though, so this might be the way to do it. See https://developer.chrome.com/extensions/messaging