From 48691ae715c097909ce1fc66d580ffe6344b0715 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Tue, 3 Dec 2019 14:50:19 +0000 Subject: [PATCH] Set 'noopener' when opening windows to avoid sharing event loops Prevents the web UI pausing when an app opened with window.open is paused in the browsers debugger. Fixes https://github.com/eclipse-theia/theia/issues/5857. Signed-off-by: Danny Tuppeny --- CHANGELOG.md | 4 ++++ packages/core/src/browser/http-open-handler.ts | 2 +- .../core/src/browser/window/default-window-service.ts | 9 +++------ packages/core/src/browser/window/window-service.ts | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7757cb4e30e1c..3bbe3704b9804 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ - [bunyan] removed [`@theia/bunyan`](https://github.com/eclipse-theia/theia/tree/b92a5673de1e9d1bdc85e6200486b92394200579/packages/bunyan) extension [#6651](https://github.com/eclipse-theia/theia/pull/6651) +Breaking changes: + +- [core] new browser windows spawned through opener-service have noopener set, preventing them from accessing window.opener and giveing them their own event loop. openNewWindow will no longer return a Window as a result. + ## v0.13.0 - [console] added filtering support based on severity [#6486](https://github.com/eclipse-theia/theia/pull/6486) diff --git a/packages/core/src/browser/http-open-handler.ts b/packages/core/src/browser/http-open-handler.ts index 875c64b047aeb..d21ec019e308c 100644 --- a/packages/core/src/browser/http-open-handler.ts +++ b/packages/core/src/browser/http-open-handler.ts @@ -35,7 +35,7 @@ export class HttpOpenHandler implements OpenHandler { return (uri.scheme.startsWith('http') || uri.scheme.startsWith('mailto')) ? 500 : 0; } - async open(uri: URI): Promise { + async open(uri: URI): Promise { const resolvedUri = await this.externalUriService.resolve(uri); return this.windowService.openNewWindow(resolvedUri.toString(true), { external: true }); } diff --git a/packages/core/src/browser/window/default-window-service.ts b/packages/core/src/browser/window/default-window-service.ts index c03ed64e1fdbc..a2948fb7a351d 100644 --- a/packages/core/src/browser/window/default-window-service.ts +++ b/packages/core/src/browser/window/default-window-service.ts @@ -41,12 +41,9 @@ export class DefaultWindowService implements WindowService, FrontendApplicationC }); } - openNewWindow(url: string): Window | undefined { - const newWindow = window.open(url); - if (newWindow === null) { - throw new Error('Cannot open a new window for URL: ' + url); - } - return newWindow; + openNewWindow(url: string): undefined { + window.open(url, undefined, 'noopener'); + return undefined; } canUnload(): boolean { diff --git a/packages/core/src/browser/window/window-service.ts b/packages/core/src/browser/window/window-service.ts index b0bcbd8bb48e0..1300b5af249c0 100644 --- a/packages/core/src/browser/window/window-service.ts +++ b/packages/core/src/browser/window/window-service.ts @@ -29,7 +29,7 @@ export interface WindowService { * In a browser, opening a new Theia tab or open a link is the same thing. * But in Electron, we want to open links in a browser, not in Electron. */ - openNewWindow(url: string, options?: NewWindowOptions): Window | undefined; + openNewWindow(url: string, options?: NewWindowOptions): undefined; /** * Called when the `window` is about to `unload` its resources.