WebExtensions API: Add clickHandler to browser.tabs.create()
Categories
(Thunderbird :: Add-Ons: Extensions API, enhancement)
Tracking
(Not tracked)
People
(Reporter: garoedp, Unassigned)
References
Details
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0
Expected results:
The WebExtensions API for browser.tabs.create() does not provide access to the clickHandler property. This is needed for my addon ThunderKeepPlus
Comment 1•5 years ago
|
||
I'm not sure exposing clickHandler
here is the right thing to do for the WebExtension world.
You can probably achieve the same functionality using a content script.
I understand that exposing additional functionally for addons is a burden for Thunderbird development and maintenance. However, injecting javascript in a website seems like an overkill method for controlling when the user is pushed to an external browser.
If that's the only option, at least it'd be really useful to port the examples that are shown in the clickHandler page to the content script site, and add link to those in the browser.tabs.create() documentation. Specially, for addon developers who are not very experienced with web technologies, like myself.
Comment 3•4 years ago
|
||
This is indeed possible with a content script. Add this to your manifest:
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content-script.js"]
}
],
You may limit the content script to a more strict match, if you know which pages you are going to use with your extension. In the content script define a global clickhandler:
window.addEventListener("click", clickhandler);
function clickhandler(event) {
event.preventDefault();
event.stopPropagation();
const anchor = event.target.closest("a");
if (!anchor) return;
window.location.href=anchor.getAttribute('href');
}
For WebExtension programming related question, you can find help at our topicbox:
https://thunderbird.topicbox.com/groups/addons
Description
•