From 9e69187c8c4b018f838d42cb6ebbf900c0cb2eb6 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Mon, 20 Jun 2022 01:03:18 +0200 Subject: fix: webview did-attach race condition (#302) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure the event handler for attached webviews runs in a separate task to avoid race conditions like https://github.com/electron/electron/issues/31918 This should hopefully fix #157 Signed-off-by: Kristóf Marussy --- src/components/services/content/ServiceWebview.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/components/services') diff --git a/src/components/services/content/ServiceWebview.js b/src/components/services/content/ServiceWebview.js index 6d6089793..66dc8af41 100644 --- a/src/components/services/content/ServiceWebview.js +++ b/src/components/services/content/ServiceWebview.js @@ -95,10 +95,18 @@ class ServiceWebview extends Component { preload={preloadScript} partition={service.partition} onDidAttach={() => { - setWebviewReference({ - serviceId: service.id, - webview: this.webview.view, - }); + // Force the event handler to run in a new task. + // This resolves a race condition when the `did-attach` is called, + // but the webview is not attached to the DOM yet: + // https://github.com/electron/electron/issues/31918 + // This prevents us from immediately attaching listeners such as `did-stop-load`: + // https://github.com/ferdium/ferdium-app/issues/157 + setTimeout(() => { + setWebviewReference({ + serviceId: service.id, + webview: this.webview.view, + }); + }, 0); }} onUpdateTargetUrl={this.updateTargetUrl} useragent={service.userAgent} -- cgit v1.2.3-54-g00ecf