提交 eab96df4 编写于 作者: M Matt Bierner

Allow cmr+r reload from webview developer tools

Fixes #48975
上级 730eb4e5
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
var loadTimeout; var loadTimeout;
var pendingMessages = []; var pendingMessages = [];
var enableWrappedPostMessage = false; var enableWrappedPostMessage = false;
let isInDevelopmentMode = false;
const initData = { const initData = {
initialScrollProgress: undefined initialScrollProgress: undefined
...@@ -89,7 +90,6 @@ ...@@ -89,7 +90,6 @@
}; };
const onMessage = (message) => { const onMessage = (message) => {
// Old school webview. Forward exact message
ipcRenderer.sendToHost(message.data.command, message.data.data); ipcRenderer.sendToHost(message.data.command, message.data.data);
}; };
...@@ -322,6 +322,12 @@ ...@@ -322,6 +322,12 @@
// write new content onto iframe // write new content onto iframe
newFrame.contentDocument.open('text/html', 'replace'); newFrame.contentDocument.open('text/html', 'replace');
newFrame.contentWindow.onbeforeunload = () => { newFrame.contentWindow.onbeforeunload = () => {
if (isInDevelopmentMode) { // Allow reloads while developing a webview
ipcRenderer.sendToHost('do-reload');
return false;
}
// Block navigation when not in development mode
console.log('prevented webview navigation'); console.log('prevented webview navigation');
return false; return false;
}; };
...@@ -395,6 +401,10 @@ ...@@ -395,6 +401,10 @@
initData.initialScrollProgress = progress; initData.initialScrollProgress = progress;
}); });
ipcRenderer.on('devtools-opened', () => {
isInDevelopmentMode = true;
});
// Forward messages from the embedded iframe // Forward messages from the embedded iframe
window.onmessage = onMessage; window.onmessage = onMessage;
......
...@@ -158,6 +158,10 @@ export class WebviewElement { ...@@ -158,6 +158,10 @@ export class WebviewElement {
this._onDidScroll.fire({ scrollYPercentage: event.args[0] }); this._onDidScroll.fire({ scrollYPercentage: event.args[0] });
} }
return; return;
case 'do-reload':
this.reload();
return;
} }
}), }),
addDisposableListener(this._webview, 'focus', () => { addDisposableListener(this._webview, 'focus', () => {
...@@ -169,7 +173,10 @@ export class WebviewElement { ...@@ -169,7 +173,10 @@ export class WebviewElement {
if (this._contextKey) { if (this._contextKey) {
this._contextKey.reset(); this._contextKey.reset();
} }
}) }),
addDisposableListener(this._webview, 'devtools-opened', () => {
this._send('devtools-opened');
}),
); );
this._webviewFindWidget = new WebviewFindWidget(this._contextViewService, this); this._webviewFindWidget = new WebviewFindWidget(this._contextViewService, this);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册