Permission error when calling openUrl(), but only with openWith parameter supplied
My app: https://github.com/cliambrown/Playa (But some of the code below has not been pushed to GitHub — still testing locally.)
The issue:
import { openUrl } from '@tauri-apps/plugin-opener';
...
openUrl('https://www.google.com/'); // ✅️ Works without errors
openUrl('https://www.google.com/', 'firefox'); // ❌️ Does not work and produces an error (see below)
The error:
Unhandled Promise Rejection: Not allowed to open url https://www.google.com/ with firefox
/src-tauri/capabilities/desktop.json
{
"identifier": "desktop-capability",
"platforms": [
"macOS",
"windows",
"linux"
],
"windows": [
"main"
],
"permissions": [
"window-state:default",
"opener:default",
{
"identifier": "opener:allow-open-url",
"allow": [
{ "url": "https://www.google.com/" }
]
},
{
"identifier": "http:default",
"allow": [
{ "url": "https://www.google.com/" }
]
},
"shell:default",
{
"identifier": "shell:allow-execute",
"allow": [
{
"name": "firefox",
"args": true,
"cmd": "firefox",
"sidecar": false
}
]
}
]
}
The documentation for the opener plugin mentions permissions to restrict URLs, but it does not mention a specific permission required to be allowed to use the openWith parameter.
While trying to make this work, I added the exact url to the http:default permission and the opener:allow-open-url permission to see if that would help (it did not). However, openUrl(url) works with any URL with no openWith value supplied and with just the "opener:allow-open-url" permission (no specific URLs allowed).
Is there some missing documentation about a permission required to be able to use the openWith parameter? (I know in v1 openWith was restricted to certain values, but that's not indicated for v2, and "firefox" was one of the allowed values in v1.)
you're right, it's indeed missing docs. the permissions have a app field which can be true, false, or a string with the name of the app.
- default / not defined: only allows calls that do not set openWith
- true: allows openWith
- false: this is a weird one as it basically disables the entry no matter if openWith is provided or not as far as i can see
- string: pretty obvious. set this to firefox to only allow calls that set openWith to "firefox"
@FabianLars Thanks very much! I was able to use openWith by adding the following permission:
{
"identifier": "opener:allow-open-url",
"allow": [
{
"url": "https://*",
"app": true
}
]
},
Now openUrl('https://www.google.com/', 'firefox') works without errors.
I think it would be useful to add this to the documentation. Thanks again for your help!
Nice :) and yes we'll absolutely add it to the docs