refactor: use the URL api to resolve urls in window setup (#18611)
This commit is contained in:
parent
bd80e68698
commit
291ee2dafc
1 changed files with 3 additions and 8 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue