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?
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
...
"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
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"
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With