Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 601
Nicholas DiPiazza Avatar asked Dec 09 '18 06:12

Nicholas DiPiazza


2 Answers

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

like image 152
Ahmad Avatar answered Oct 02 '22 10:10

Ahmad


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"
],
like image 20
Rubin bhandari Avatar answered Oct 02 '22 12:10

Rubin bhandari