Leo
Leo

Reputation: 13848

Can Chrome extension content script access all tabs?

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?

Upvotes: 3

Views: 3219

Answers (1)

Erich Kitzmueller
Erich Kitzmueller

Reputation: 36987

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

Upvotes: 3

Related Questions