Closed Bug 1618828 Opened 4 years ago Closed 4 years ago

WebExtensions API: Add clickHandler to browser.tabs.create()

Categories

(Thunderbird :: Add-Ons: Extensions API, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED WONTFIX

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

Blocks: webext-tb

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.

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

Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.