javascriptgoogle-chrome-extensionbrowserfirefox-addonfirefox-addon-webextensions

How to open a deeplink without creating a new tab or window in a web extension


I have an anchor tag which when selected should open a link to an external application (Obsidian). Here's an example link: obsidian://action?param1=value&param2=value.

I expect that clicking on the anchor opens the external application without creating windows or tabs.

Current Browsers:

Current Permissions:

I'm trying to avoid hosts_permissions if possible.

Several tried methods:

In the below examples, my usage of the "browser" namespace is equivalent to the chrome namespace.

Maybe there is another way or something I didn't think of like being able to resize the prompt window?


Solution

  • After some more research I have found that browser.tabs.update() is perfect for my use-case! It calls the deep-link without opening a new tab or window and somehow avoids changing the tab URL. I assume the foreign protocol has something to do with this.

    In my extension setup, I am calling this directly in the popup from an anchor tag.

    Example:

    async function openDeeplink(deeplink) {
         const [activeTab] = await browser.tabs.query({active: true, currentWindow:true});
         browser.tabs.update(activeTab.id, { url: deeplink });
    }