Skip to content
Permalink
Browse files

refactor: use the URL api to resolve urls in window setup (#18611)

  • Loading branch information...
nornagon committed Jun 5, 2019
1 parent bd80e68 commit 291ee2dafc5f62d05587a754222477414c66174f
Showing with 3 additions and 8 deletions.
  1. +3 −8 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) {

0 comments on commit 291ee2d

Please sign in to comment.
You can’t perform that action at this time.