Merge pull request #15 from Stremio/feat/webview-handle-window-open

feat(webview): handle window.open
This commit is contained in:
Владимир Борисов 2025-03-24 17:03:03 +02:00 committed by GitHub
commit 38d52a3c6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -137,6 +137,24 @@ impl PartialUi for WebView {
}
})
}catch(e){}
window.open = (url) => {
if (typeof url === 'string' && URL.canParse(url)) {
try {
const message = {
id: 1,
args: ['open-external', url],
};
window.chrome.webview.postMessage(JSON.stringify(message));
} catch(e) {
console.error('Failed to post message');
}
} else {
return console.error('Not a valid URL string');
}
};
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));