feat(webview): handle window.open

This commit is contained in:
Tim 2025-01-31 17:40:05 +01:00
parent c037255614
commit ae5e8eb0e4

View file

@ -137,6 +137,23 @@ impl PartialUi for WebView {
}
})
}catch(e){}
window.open = (url) => {
if (typeof url === 'string' && URL.canParse(url))
return console.error('Not a valid URL string');
try {
const message = {
id: 1,
args: ['open-external', url],
};
window.chrome.webview.postMessage(JSON.stringify(message));
} catch(e) {
console.error('Failed to post message');
}
};
try{console.log('Shell JS injected');if(window.self === window.top) {
window.qt={webChannelTransport:{send:window.chrome.webview.postMessage}};
window.chrome.webview.addEventListener('message',ev=>window.qt.webChannelTransport.onmessage(ev));