Opening a browser from Theia

Hello,

What is the easiest way to open up a browser tab (the browser would be whatever the user’s default is) directly from Theia? Alternatively, is there a way to re-configure the mini-browser extension so it travels to a link (instead of opening up an HTML file)?

Thanks for the help,
Kaustav Das Sharma.

You could use the OpenerService.

Something like this (not a complete working solution but you’ll get the gist of it):

First, import OpenerService and URI:

import { OpenerService } from '@theia/core/lib/browser';
import URI from '@theia/core/lib/common/uri';

then, inject the service:

@inject(OpenerService)
private openerService: OpenerService;

you could then create a function like this one:

private async openLink(link: string): Promise<void> {        
    const opener = await this.openerService.getOpener(new URI(link));
    opener.open(uri);
}

and call it from your code:

this.openLink(yourLink);
2 Likes