C. Yoo
C. Yoo

Reputation: 107

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.

Upvotes: 4

Views: 3980

Answers (2)

Satish Kumar sonker
Satish Kumar sonker

Reputation: 1288

As i understand you are creating site specific extension. in that case set the site specific permission in manifest.json file.

"permissions":          ["https://WhateverYourSite/*","activetab"]

Upvotes: 0

Xan
Xan

Reputation: 77523

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.

Upvotes: 2

Related Questions