Posts
Posts
Having a userscript in Firefox open an external app, without needing to always click yes

Having a userscript in Firefox open an external app, without needing to always click yes

Let's say you're making a userscript that opens some external app. Let's say Discord.

So you put this code into your userscript:

JavaScript
location.assign("discord://-");

Okay neat. But when it executes, you're greeted with this:

Screenshot of Firefox. "Allow this site to open the discord link with Discord?" There is no always allow checkbox.

There's no checkbox to have it always open in Discord, like it usually does with some other apps. How inconvenient!

Screenshot of Firefox. "Allow https://www.roblox.com open the roblox-player link with Roblox Game Client?" The always allow checkbox is present.
Roblox, for example

Fixing this

From what I can tell, the issue is due to your userscript manager technically being the one trying to open the app. Firefox likely doesn't support storing the "always allow" option for your userscript manager, so it's just not present.

It's an easy fix though!

In your header, grant unsafeWindow:

  // ==UserScript==
  // @name         New Userscript
  // @namespace    http://tampermonkey.net/
  // @version      2025-05-26
  // @description  try to take over the world!
  // @author       You
  // @match        *://*/*
+ // @grant        unsafeWindow
  // ==/UserScript==

And in your code, use the location.assign on unsafeWindow instead:

JavaScript
unsafeWindow.location.assign("discord://-");

That's it! It should let you always allow it now:

Screenshot of Firefox. "Allow this site to open the discord link with Discord?" The always allow checkbox is now present.