5

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?

Nicholas DiPiazza
  • 10,029
  • 11
  • 83
  • 152
  • Which event will cause said sidebar to appear, and which events causes it to be hidden? – Ahmad Dec 09 '18 at 06:53
  • page navigation only. in my example, if they have navigated to `google.com` the sidebar appears. otherwise, it disappears. or perhaps, if the URL they have visited matches a regex such as `.*\/event\/.*` – Nicholas DiPiazza Dec 09 '18 at 06:54
  • so, as long as the user is on google.com, the side bar should be visible, and as soon as he/she visits another domain, the sidebar should go away. Is that right? – Ahmad Dec 09 '18 at 06:55
  • yep. i think in my real use case, it will be whenever a user navigates to a page who's url matches a regex – Nicholas DiPiazza Dec 09 '18 at 06:56

2 Answers2

7

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

Ahmad
  • 12,336
  • 6
  • 48
  • 88
1

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"
],
Rubin bhandari
  • 1,873
  • 15
  • 20