How to open URL in default browser from plugin?

I have one general questions regarding URLs.

I want to implement a command to open the source_url in the default browser. But I couldn't get it running. It seems the plugin has no access to electron packages (e.g. shell, bridge) and other npm package (e.g. open, https://www.npmjs.com/package/open) also not work for me.

So, how can I open an URL in the default browser? Or rather, any other type of URL in the corresponding application/process?

This is how my command currently looks like:

await joplin.commands.register({
  name: 'openURLInBrowser',
  label: 'Open URL in browser',
  iconName: 'fas fa-globe',
  enabledCondition: "oneNoteSelected",
  execute: async () => {
    /* get the selected note and exit if none is currently selected */
    const selectedNote = await joplin.workspace.selectedNote();
    if (!selectedNote) return;
    /* exit if 'source_url' is not set for note */
    if (!selectedNote.source_url) return;

    /* open URL in default browser */
    // 1: from joplin code - does not work
    // const bridge = require('electron').remote.require('./bridge').default;
    // bridge().openExternal('https://www.npmjs.com/package/open');

    // 2: electron shell - does not work
    // const { shell } = require('electron');
    // shell.openExternal('https://github.com');

    // 3: npm open - does not work
    // https://github.com/pwnall/node-open
    // https://www.npmjs.com/package/open
    // first: npm install open
    // const open = require('open');
    // await open('https://github.com');
    // await open(note.source_url);

    // 4: built in open command - does not work
    // open('https://www.google.com', '_blank');
    open(selectedNote.source_url, '_blank');
  },
});

did you ever solve this?

I'm happy to improve the plugin API to add such features (it's relatively easy to do so), but the problem is that there's no way to track these various requests so they end up being forgotten.

Whenever you are missing a feature, please create an issue on GitHub, which we can then label and add to the backlog. For example, opening an external URL is definitely something we'd want to support

1 Like

Thanks. FYI the github issues feature requests goes straight back here to the forum. I'll file it as a bug for now

issue is here

1 Like

await joplin.commands.execute('openItem', url);

appears to work