Nicholas DiPiazza
Nicholas DiPiazza

Reputation: 10595

Configuring a sidebar_action to be only on for certain sites?

I want to create a firefox extension that allows a sidebar to automatically show when a user navigates to certain web pages.

For example, let's say I configure it so if a user navigates to google.com they will be presented a sidebar that lets them see some "previous searches" they had done.

I do not want them to have to click a menu action / keyboard shortcut to display it. And I do not want to display it indefinitely.

I've been looking at these links to learn how to use sidebars:

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Sidebars

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/sidebar_action

https://github.com/mdn/webextensions-examples/tree/master/annotate-page

But they do not seem to cover how to hide/show sidebars conditionally. They are just kinda, always shown. Not really what I want.

Is there a way to use sidebars in this way or should I use another method?

Upvotes: 6

Views: 353

Answers (2)

Rubin bhandari
Rubin bhandari

Reputation: 1951

This can be achieved by specifying hosts which can be either one of a list of known strings (such as "geolocation") or a match pattern that gives access to one or more hosts.

Here's an example of the permissions part of a manifest file:

"permissions": [
  "tabs",
  "bookmarks",
  "http://www.blogger.com/",
  "http://*.google.com/",
  "unlimitedStorage"
],

Upvotes: 1

Ahmad
Ahmad

Reputation: 12737

You can control when your extension is inserted into the currently visited page (thus, causing your sidebar to appear) or not based on the permission settings in the manifest file

manifest.json

...
"permissions": [
  ... 
  "http://*.google.com/",
  "http://*event*/",
  ...
],

In the above example, the extension will work only on google.com as well as any domain containing the word event. If you want to target domains where the word event appear as part of the path, then you would use something like

"http://*/*event*/*",

You get the idea.

For more information read Google's Extension Development - Declare Permissions

Upvotes: 7

Related Questions