Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a Google Chrome Extension work on only one tab

Is there a way to set up a google chrome extension (maybe in the manifest?) so that it only functions on exactly one tab? That way, I can let my extension do things on that one tab while I take care of other work on another tab.

I need this ability because my extension pretty much sits on a website and is constantly refreshing the page, looking for updates.

EDIT

Although I cannot display the code of the extension due to a privacy policy, I can explain what it exactly does. For localbitcoins.com, the extension searches for an un-read message notification on the page, and refreshes every 3 seconds to search over and over again. If an unread message is found, it redirects the current URL to the link provided by the notification. From there, it identifies an html form, fills an <input> tag with a message, submits the form, and then returns back to the home page, once again searching for new messages. Again, refreshing every 3 seconds.

like image 634
C. Yoo Avatar asked Oct 26 '25 10:10

C. Yoo


1 Answers

I suppose your extension works by injecting a content script via the manifest.

You can instead make an extension with a Browser Action that will, on click, open a tab and then take care of the content scripts by programmatic injection.

That way, even if you open another tab with the same site, the content script won't be injected there.

Alternatively, you can always inject a content script but only "activate" it from the background page.

This is only a very high-level overview, but your question is light on details.

In any case, you'll need a background page + messaging, since only the background page is aware of tab IDs.

like image 126
Xan Avatar answered Oct 29 '25 00:10

Xan