From 291ee2dafc5f62d05587a754222477414c66174f Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Wed, 5 Jun 2019 10:21:06 -0700 Subject: [PATCH] refactor: use the URL api to resolve urls in window setup (#18611) --- lib/renderer/window-setup.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/renderer/window-setup.ts b/lib/renderer/window-setup.ts index bfb248e3269..d3ae5e2895f 100644 --- a/lib/renderer/window-setup.ts +++ b/lib/renderer/window-setup.ts @@ -20,12 +20,7 @@ import { ipcRendererInternal } from '@electron/internal/renderer/ipc-renderer-in const { defineProperty } = Object // Helper function to resolve relative url. -let a: HTMLAnchorElement -const resolveURL = function (url: string) { - a = a || window.document.createElement('a') - a.href = url - return a.href -} +const resolveURL = (url: string, base: string) => new URL(url, base).href // Use this method to ensure values expected as strings in the main process // are convertible to strings in the renderer process. This ensures exceptions @@ -129,7 +124,7 @@ class BrowserWindowProxy { return this._location } public set location (url: string | any) { - url = resolveURL(url) + url = resolveURL(url, this.location.href) this._invokeWebContentsMethodSync('loadURL', url) } @@ -194,7 +189,7 @@ export const windowSetup = ( // Make the browser window or guest view emit "new-window" event. (window as any).open = function (url?: string, frameName?: string, features?: string) { if (url != null && url !== '') { - url = resolveURL(url) + url = resolveURL(url, location.href) } const guestId = ipcRendererInternal.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, toString(frameName), toString(features)) if (guestId != null) {