fix(page): Page.goto should properly handle historyAPI in beforeunload (#3198)

Fixes #2764.
This commit is contained in:
Andrey Lushnikov
2018-09-05 22:59:29 +01:00
committed by GitHub
parent 28d92116b7
commit d54c7edeae
3 changed files with 50 additions and 29 deletions

View File

@@ -51,16 +51,36 @@ class NavigatorWatcher {
helper.addEventListener(this._frameManager, FrameManager.Events.FrameDetached, this._checkLifecycleComplete.bind(this))
];
const lifecycleCompletePromise = new Promise(fulfill => {
this._lifecycleCompleteCallback = fulfill;
this._sameDocumentNavigationPromise = new Promise(fulfill => {
this._sameDocumentNavigationCompleteCallback = fulfill;
});
this._navigationPromise = Promise.race([
this._createTimeoutPromise(),
lifecycleCompletePromise
]).then(error => {
this._cleanup();
return error;
this._newDocumentNavigationPromise = new Promise(fulfill => {
this._newDocumentNavigationCompleteCallback = fulfill;
});
this._timeoutPromise = this._createTimeoutPromise();
}
/**
* @return {!Promise<?Error>}
*/
sameDocumentNavigationPromise() {
return this._sameDocumentNavigationPromise;
}
/**
* @return {!Promise<?Error>}
*/
newDocumentNavigationPromise() {
return this._newDocumentNavigationPromise;
}
/**
* @return {!Promise<?Error>}
*/
timeoutPromise() {
return this._timeoutPromise;
}
/**
@@ -74,13 +94,6 @@ class NavigatorWatcher {
.then(() => new TimeoutError(errorMessage));
}
/**
* @return {!Promise<?Error>}
*/
async navigationPromise() {
return this._navigationPromise;
}
/**
* @param {!Puppeteer.Frame} frame
*/
@@ -97,7 +110,10 @@ class NavigatorWatcher {
return;
if (!checkLifecycle(this._frame, this._expectedLifecycle))
return;
this._lifecycleCompleteCallback();
if (this._hasSameDocumentNavigation)
this._sameDocumentNavigationCompleteCallback();
if (this._frame._loaderId !== this._initialLoaderId)
this._newDocumentNavigationCompleteCallback();
/**
* @param {!Puppeteer.Frame} frame
@@ -117,13 +133,8 @@ class NavigatorWatcher {
}
}
cancel() {
this._cleanup();
}
_cleanup() {
dispose() {
helper.removeEventListeners(this._eventListeners);
this._lifecycleCompleteCallback(new Error('Navigation failed'));
clearTimeout(this._maximumTimer);
}
}