Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 878
Leo Avatar asked Mar 20 '26 22:03

Leo


1 Answers

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

like image 181
Erich Kitzmueller Avatar answered Mar 22 '26 17:03

Erich Kitzmueller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!