fix: handle asynchronous URL loading in bw proxy (#23776)
This commit is contained in:
parent
ca6a415626
commit
f78504515b
3 changed files with 10 additions and 6 deletions
|
@ -907,10 +907,10 @@ Returns `String` - The URL of the current web page.
|
||||||
```javascript
|
```javascript
|
||||||
const { BrowserWindow } = require('electron')
|
const { BrowserWindow } = require('electron')
|
||||||
let win = new BrowserWindow({ width: 800, height: 600 })
|
let win = new BrowserWindow({ width: 800, height: 600 })
|
||||||
win.loadURL('http://github.com')
|
win.loadURL('http://github.com').then(() => {
|
||||||
|
const currentURL = win.webContents.getURL()
|
||||||
let currentURL = win.webContents.getURL()
|
console.log(currentURL)
|
||||||
console.log(currentURL)
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `contents.getTitle()`
|
#### `contents.getTitle()`
|
||||||
|
|
|
@ -125,7 +125,11 @@ class LocationProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
private getGuestURL (): URL | null {
|
private getGuestURL (): URL | null {
|
||||||
const urlString = this._invokeWebContentsMethodSync('getURL') as string;
|
const maybeURL = this._invokeWebContentsMethodSync('getURL') as string;
|
||||||
|
|
||||||
|
// When there's no previous frame the url will be blank, so accountfor that here
|
||||||
|
// to prevent url parsing errors on an empty string.
|
||||||
|
const urlString = maybeURL !== '' ? maybeURL : 'about:blank';
|
||||||
try {
|
try {
|
||||||
return new URL(urlString);
|
return new URL(urlString);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -4128,7 +4128,7 @@ describe('BrowserWindow module', () => {
|
||||||
window.postMessage({openedLocation}, '*')
|
window.postMessage({openedLocation}, '*')
|
||||||
`);
|
`);
|
||||||
const [, data] = await p;
|
const [, data] = await p;
|
||||||
expect(data.pageContext.openedLocation).to.equal('');
|
expect(data.pageContext.openedLocation).to.equal('about:blank');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue