mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: do not use loaderId for Lifecycle events (#8353)
This commit is contained in:
parent
74380303ac
commit
7107d2d300
@ -194,7 +194,6 @@ export class FrameManager extends EventEmitter {
|
|||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
const watcher = new LifecycleWatcher(this, frame, waitUntil, timeout);
|
const watcher = new LifecycleWatcher(this, frame, waitUntil, timeout);
|
||||||
let ensureNewDocumentNavigation = false;
|
|
||||||
let error = await Promise.race([
|
let error = await Promise.race([
|
||||||
navigate(this._client, url, referer, frame._id),
|
navigate(this._client, url, referer, frame._id),
|
||||||
watcher.timeoutOrTerminationPromise(),
|
watcher.timeoutOrTerminationPromise(),
|
||||||
@ -202,9 +201,8 @@ export class FrameManager extends EventEmitter {
|
|||||||
if (!error) {
|
if (!error) {
|
||||||
error = await Promise.race([
|
error = await Promise.race([
|
||||||
watcher.timeoutOrTerminationPromise(),
|
watcher.timeoutOrTerminationPromise(),
|
||||||
ensureNewDocumentNavigation
|
watcher.newDocumentNavigationPromise(),
|
||||||
? watcher.newDocumentNavigationPromise()
|
watcher.sameDocumentNavigationPromise(),
|
||||||
: watcher.sameDocumentNavigationPromise(),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
watcher.dispose();
|
watcher.dispose();
|
||||||
@ -223,7 +221,6 @@ export class FrameManager extends EventEmitter {
|
|||||||
referrer,
|
referrer,
|
||||||
frameId,
|
frameId,
|
||||||
});
|
});
|
||||||
ensureNewDocumentNavigation = !!response.loaderId;
|
|
||||||
return response.errorText
|
return response.errorText
|
||||||
? new Error(`${response.errorText} at ${url}`)
|
? new Error(`${response.errorText} at ${url}`)
|
||||||
: null;
|
: null;
|
||||||
|
@ -64,7 +64,6 @@ export class LifecycleWatcher {
|
|||||||
_timeout: number;
|
_timeout: number;
|
||||||
_navigationRequest?: HTTPRequest;
|
_navigationRequest?: HTTPRequest;
|
||||||
_eventListeners: PuppeteerEventListener[];
|
_eventListeners: PuppeteerEventListener[];
|
||||||
_initialLoaderId: string;
|
|
||||||
|
|
||||||
_sameDocumentNavigationPromise: Promise<Error | null>;
|
_sameDocumentNavigationPromise: Promise<Error | null>;
|
||||||
_sameDocumentNavigationCompleteCallback: (x?: Error) => void;
|
_sameDocumentNavigationCompleteCallback: (x?: Error) => void;
|
||||||
@ -82,6 +81,7 @@ export class LifecycleWatcher {
|
|||||||
|
|
||||||
_maximumTimer?: NodeJS.Timeout;
|
_maximumTimer?: NodeJS.Timeout;
|
||||||
_hasSameDocumentNavigation?: boolean;
|
_hasSameDocumentNavigation?: boolean;
|
||||||
|
_newDocumentNavigation?: boolean;
|
||||||
_swapped?: boolean;
|
_swapped?: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -100,7 +100,6 @@ export class LifecycleWatcher {
|
|||||||
|
|
||||||
this._frameManager = frameManager;
|
this._frameManager = frameManager;
|
||||||
this._frame = frame;
|
this._frame = frame;
|
||||||
this._initialLoaderId = frame._loaderId;
|
|
||||||
this._timeout = timeout;
|
this._timeout = timeout;
|
||||||
this._navigationRequest = null;
|
this._navigationRequest = null;
|
||||||
this._eventListeners = [
|
this._eventListeners = [
|
||||||
@ -122,6 +121,11 @@ export class LifecycleWatcher {
|
|||||||
FrameManagerEmittedEvents.FrameNavigatedWithinDocument,
|
FrameManagerEmittedEvents.FrameNavigatedWithinDocument,
|
||||||
this._navigatedWithinDocument.bind(this)
|
this._navigatedWithinDocument.bind(this)
|
||||||
),
|
),
|
||||||
|
helper.addEventListener(
|
||||||
|
this._frameManager,
|
||||||
|
FrameManagerEmittedEvents.FrameNavigated,
|
||||||
|
this._navigated.bind(this)
|
||||||
|
),
|
||||||
helper.addEventListener(
|
helper.addEventListener(
|
||||||
this._frameManager,
|
this._frameManager,
|
||||||
FrameManagerEmittedEvents.FrameSwapped,
|
FrameManagerEmittedEvents.FrameSwapped,
|
||||||
@ -217,6 +221,12 @@ export class LifecycleWatcher {
|
|||||||
this._checkLifecycleComplete();
|
this._checkLifecycleComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_navigated(frame: Frame): void {
|
||||||
|
if (frame !== this._frame) return;
|
||||||
|
this._newDocumentNavigation = true;
|
||||||
|
this._checkLifecycleComplete();
|
||||||
|
}
|
||||||
|
|
||||||
_frameSwapped(frame: Frame): void {
|
_frameSwapped(frame: Frame): void {
|
||||||
if (frame !== this._frame) return;
|
if (frame !== this._frame) return;
|
||||||
this._swapped = true;
|
this._swapped = true;
|
||||||
@ -227,19 +237,9 @@ export class LifecycleWatcher {
|
|||||||
// We expect navigation to commit.
|
// We expect navigation to commit.
|
||||||
if (!checkLifecycle(this._frame, this._expectedLifecycle)) return;
|
if (!checkLifecycle(this._frame, this._expectedLifecycle)) return;
|
||||||
this._lifecycleCallback();
|
this._lifecycleCallback();
|
||||||
if (
|
|
||||||
this._frame._loaderId === this._initialLoaderId &&
|
|
||||||
!this._hasSameDocumentNavigation
|
|
||||||
) {
|
|
||||||
if (this._swapped) {
|
|
||||||
this._swapped = false;
|
|
||||||
this._newDocumentNavigationCompleteCallback();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this._hasSameDocumentNavigation)
|
if (this._hasSameDocumentNavigation)
|
||||||
this._sameDocumentNavigationCompleteCallback();
|
this._sameDocumentNavigationCompleteCallback();
|
||||||
if (this._frame._loaderId !== this._initialLoaderId)
|
if (this._swapped || this._newDocumentNavigation)
|
||||||
this._newDocumentNavigationCompleteCallback();
|
this._newDocumentNavigationCompleteCallback();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user