Shimmy Weitzhandler
Shimmy Weitzhandler

Reputation: 104821

Chrome extension that runs in the background on window open event?

How can I make a Chrome extensions that is not a popup or a button?

  1. I wanna have a script running whenever the window is opened and iterate thru all its tabs performing actions on each tab.
  2. I also need (is this possible?) want to add to the same extension buttons (+keyboard shortcuts?) that when clicked, perform actions on all tabs.
  3. Then I need control on these buttons visibility, and make them visible only in certain conditions (e.g. show only when page is loading, hide when not-loading).

Where do I put my script and how do I refer to it in my *.json manifest?

Any info/links will be appreciated.

Upvotes: 2

Views: 2905

Answers (1)

Rob W
Rob W

Reputation: 349222

The answers to 0 and 1 can directly be found in the documentation, specifically background pages, chrome.windows API and chrome.tabs API.

To bind global events, use the chrome.experimental.keybinding API. Because this API is experimental, you have to enable it first at chrome://flags. Also, the extension cannot be uploaded to the Chrome Web store.
If you want to add an "extension button" which performs some action on click, define a browser action and bind an event listener to chrome.browserAction.onClicked.
To select all tabs, use chrome.tabs.query({}, callback) method ({} means no filter, so all tabs are selected).

Browser action buttons are always visible. If you want to create a button which is not always visible, use a page action instead. The chrome.tabs module includes several events which can be used to find out whether your conditions are met.

As for putting up the script and the manifest file, read the documentation on Manifest files and explore some examples.

Upvotes: 7

Related Questions