I’m working on a custom Obsidian plugin and would like to programmatically open the latest version of the Web Viewer core plugin (v1.8.3). My goal is to create a new Web Viewer tab and load a specified URL through code.
The regular JS API window.open("https://example.com") will automatically open the page in the web viewer, if it’s disabled it will load in the default browser instead.
// set paneType to be "tab" if you want to open in a new tab
const leaf = this.app.workspace.getLeaf(paneType);
await leaf.setViewState({
type: 'webviewer',
state: {
url: 'https://obsidian.md',
navigate: true,
},
active: true,
});