Skip to content

Commit

Permalink
Defer webview loading until all listeners have definitely been hooked…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
mjbvz committed Jun 17, 2020
1 parent b95968e commit 2c53ad1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/vs/workbench/contrib/webview/browser/webviewElement.ts
Expand Up @@ -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%';
Expand Down
Expand Up @@ -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);
Expand Down

0 comments on commit 2c53ad1

Please sign in to comment.