revert: promise resolved too early when browser initiates in-page navigation (#39481)
This reverts commit a0effaf9b8
.
This commit is contained in:
parent
f16dffccd0
commit
117d5310f5
3 changed files with 2 additions and 32 deletions
|
@ -446,7 +446,6 @@ WebContents.prototype.loadURL = function (url, options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let navigationStarted = false;
|
let navigationStarted = false;
|
||||||
let browserInitiatedInPageNavigation = false;
|
|
||||||
const navigationListener = (event: Electron.Event, url: string, isSameDocument: boolean, isMainFrame: boolean) => {
|
const navigationListener = (event: Electron.Event, url: string, isSameDocument: boolean, isMainFrame: boolean) => {
|
||||||
if (isMainFrame) {
|
if (isMainFrame) {
|
||||||
if (navigationStarted && !isSameDocument) {
|
if (navigationStarted && !isSameDocument) {
|
||||||
|
@ -461,7 +460,6 @@ WebContents.prototype.loadURL = function (url, options) {
|
||||||
// as the routing does not leave the document
|
// as the routing does not leave the document
|
||||||
return rejectAndCleanup(-3, 'ERR_ABORTED', url);
|
return rejectAndCleanup(-3, 'ERR_ABORTED', url);
|
||||||
}
|
}
|
||||||
browserInitiatedInPageNavigation = navigationStarted && isSameDocument;
|
|
||||||
navigationStarted = true;
|
navigationStarted = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -476,22 +474,17 @@ WebContents.prototype.loadURL = function (url, options) {
|
||||||
// would be more appropriate.
|
// would be more appropriate.
|
||||||
rejectAndCleanup(-2, 'ERR_FAILED', url);
|
rejectAndCleanup(-2, 'ERR_FAILED', url);
|
||||||
};
|
};
|
||||||
const finishListenerWhenUserInitiatedNavigation = () => {
|
|
||||||
if (!browserInitiatedInPageNavigation) {
|
|
||||||
finishListener();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const removeListeners = () => {
|
const removeListeners = () => {
|
||||||
this.removeListener('did-finish-load', finishListener);
|
this.removeListener('did-finish-load', finishListener);
|
||||||
this.removeListener('did-fail-load', failListener);
|
this.removeListener('did-fail-load', failListener);
|
||||||
this.removeListener('did-navigate-in-page', finishListenerWhenUserInitiatedNavigation);
|
this.removeListener('did-navigate-in-page', finishListener);
|
||||||
this.removeListener('did-start-navigation', navigationListener);
|
this.removeListener('did-start-navigation', navigationListener);
|
||||||
this.removeListener('did-stop-loading', stopLoadingListener);
|
this.removeListener('did-stop-loading', stopLoadingListener);
|
||||||
this.removeListener('destroyed', stopLoadingListener);
|
this.removeListener('destroyed', stopLoadingListener);
|
||||||
};
|
};
|
||||||
this.on('did-finish-load', finishListener);
|
this.on('did-finish-load', finishListener);
|
||||||
this.on('did-fail-load', failListener);
|
this.on('did-fail-load', failListener);
|
||||||
this.on('did-navigate-in-page', finishListenerWhenUserInitiatedNavigation);
|
this.on('did-navigate-in-page', finishListener);
|
||||||
this.on('did-start-navigation', navigationListener);
|
this.on('did-start-navigation', navigationListener);
|
||||||
this.on('did-stop-loading', stopLoadingListener);
|
this.on('did-stop-loading', stopLoadingListener);
|
||||||
this.on('destroyed', stopLoadingListener);
|
this.on('destroyed', stopLoadingListener);
|
||||||
|
|
|
@ -375,16 +375,6 @@ describe('webContents module', () => {
|
||||||
await expect(w.loadURL(w.getURL() + '#foo')).to.eventually.be.fulfilled();
|
await expect(w.loadURL(w.getURL() + '#foo')).to.eventually.be.fulfilled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('resolves after browser initiated navigation', async () => {
|
|
||||||
let finishedLoading = false;
|
|
||||||
w.webContents.on('did-finish-load', function () {
|
|
||||||
finishedLoading = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
await w.loadFile(path.join(fixturesPath, 'pages', 'navigate_in_page_and_wait.html'));
|
|
||||||
expect(finishedLoading).to.be.true();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('rejects when failing to load a file URL', async () => {
|
it('rejects when failing to load a file URL', async () => {
|
||||||
await expect(w.loadURL('file:non-existent')).to.eventually.be.rejected()
|
await expect(w.loadURL('file:non-existent')).to.eventually.be.rejected()
|
||||||
.and.have.property('code', 'ERR_FILE_NOT_FOUND');
|
.and.have.property('code', 'ERR_FILE_NOT_FOUND');
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
<html>
|
|
||||||
<header>
|
|
||||||
<script type="text/javascript">
|
|
||||||
window.history.replaceState(window.location.href, "Sample Title", window.location.href);
|
|
||||||
// Simulate that we load web page.
|
|
||||||
for (let i = 0; i < 10000; i++) {
|
|
||||||
console.log('wait : ' + i);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</header>
|
|
||||||
<body>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
Reference in a new issue