Electron provides a `new-window` event in the main thread, but TAURI does not.
Describe the problem
The following are window-wide event handlers available in Electron that are triggered when a URL is opened in a new window.
const electron = require("electron");
const shell = electron.shell;
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
app.on('ready', function() {
const mainWindow = new BrowserWindow({width: 1600, height: 600});
mainWindow.loadURL('file://' + __dirname + '/index.html');
// New window event intercepted and opened in default browser (currently not concerned with page transitions)
mainWindow.webContents.on('new-window', function(e,url){
e.preventDefault();
shell.openExternal(url);
});
});
However, these events have not yet been implemented in TAURI as far as I can tell.
This event is required when external HTML containing an a tag is loaded and displayed, for example, or when a URL is opened in an iframe (e.g., YouTube embedding) tag.
I am currently working on a project for such a situation.
It is inefficient to change the a tag in JavaScript and add the target="_blank" attribute each time.
Describe the solution you'd like
So I would like to add a new-window event in the listen function in the TAURI API.
import { listen, type Event } from '@tauri-apps/api/event';
import { Open } from '@tauri-apps/api/shell;
const winPosUnlisten = await listen("tauri://new-window", async (e: Event<{ url: string }>) => {
e.preventDefault();
await Open( url );
});
Alternatives considered
No response
Additional context
Please let me know if there are other existing methods that would be better. Thank you very much.