Defer webview loading until all listeners have definitely been hooked up on

Since webviews load on a different process, it may be possible that they load and start firing events before we have hooked up all the listeners we are interested in.

To fix, this defer setting the actual content on the webview until the listeners have been hooked up for sure

Possible cause of #98746 but since I can't repo  I can't confirm
This commit is contained in:
Matt Bierner 2020-06-17 16:02:33 -07:00
parent b95968eafb
commit 2c53ad120d
2 changed files with 10 additions and 2 deletions

View file

@ -59,13 +59,16 @@ export class IFrameWebview extends BaseWebview<HTMLIFrameElement> implements Web
this._register(this.on(WebviewMessageChannels.loadLocalhost, (entry: any) => {
this.localLocalhost(entry.origin);
}));
this.element!.setAttribute('src', `${this.externalEndpoint}/index.html?id=${this.id}`);
}
protected createElement(options: WebviewOptions, contentOptions: WebviewContentOptions) {
protected createElement(options: WebviewOptions, _contentOptions: WebviewContentOptions) {
// Do not start loading the webview yet.
// Wait the end of the ctor when all listeners have been hooked up.
const element = document.createElement('iframe');
element.className = `webview ${options.customClasses || ''}`;
element.sandbox.add('allow-scripts', 'allow-same-origin', 'allow-forms');
element.setAttribute('src', `${this.externalEndpoint}/index.html?id=${this.id}`);
element.style.border = 'none';
element.style.width = '100%';
element.style.height = '100%';

View file

@ -267,9 +267,14 @@ export class ElectronWebviewBasedWebview extends BaseWebview<WebviewTag> impleme
this.styledFindWidget();
}
this.element!.preload = require.toUrl('./pre/electron-index.js');
this.element!.src = 'data:text/html;charset=utf-8,%3C%21DOCTYPE%20html%3E%0D%0A%3Chtml%20lang%3D%22en%22%20style%3D%22width%3A%20100%25%3B%20height%3A%20100%25%22%3E%0D%0A%3Chead%3E%0D%0A%3Ctitle%3EVirtual%20Document%3C%2Ftitle%3E%0D%0A%3C%2Fhead%3E%0D%0A%3Cbody%20style%3D%22margin%3A%200%3B%20overflow%3A%20hidden%3B%20width%3A%20100%25%3B%20height%3A%20100%25%22%20role%3D%22document%22%3E%0D%0A%3C%2Fbody%3E%0D%0A%3C%2Fhtml%3E';
}
protected createElement(options: WebviewOptions) {
// Do not start loading the webview yet.
// Wait the end of the ctor when all listeners have been hooked up.
const element = document.createElement('webview');
this._elementFocusImpl = element.focus.bind(element);