mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: migrate FrameManager events from Events.ts (#6179)
This commit is contained in:
parent
6ee7139704
commit
74cb2ce7c2
@ -17,7 +17,6 @@
|
|||||||
import { EventEmitter } from './EventEmitter';
|
import { EventEmitter } from './EventEmitter';
|
||||||
import { assert } from './assert';
|
import { assert } from './assert';
|
||||||
import { helper, debugError } from './helper';
|
import { helper, debugError } from './helper';
|
||||||
import { Events } from './Events';
|
|
||||||
import { ExecutionContext, EVALUATION_SCRIPT_URL } from './ExecutionContext';
|
import { ExecutionContext, EVALUATION_SCRIPT_URL } from './ExecutionContext';
|
||||||
import { LifecycleWatcher, PuppeteerLifeCycleEvent } from './LifecycleWatcher';
|
import { LifecycleWatcher, PuppeteerLifeCycleEvent } from './LifecycleWatcher';
|
||||||
import { DOMWorld, WaitForSelectorOptions } from './DOMWorld';
|
import { DOMWorld, WaitForSelectorOptions } from './DOMWorld';
|
||||||
@ -37,6 +36,24 @@ import {
|
|||||||
|
|
||||||
const UTILITY_WORLD_NAME = '__puppeteer_utility_world__';
|
const UTILITY_WORLD_NAME = '__puppeteer_utility_world__';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We use symbols to prevent external parties listening to these events.
|
||||||
|
* They are internal to Puppeteer.
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
export const FrameManagerEmittedEvents = {
|
||||||
|
FrameAttached: Symbol('FrameManager.FrameAttached'),
|
||||||
|
FrameNavigated: Symbol('FrameManager.FrameNavigated'),
|
||||||
|
FrameDetached: Symbol('FrameManager.FrameDetached'),
|
||||||
|
LifecycleEvent: Symbol('FrameManager.LifecycleEvent'),
|
||||||
|
FrameNavigatedWithinDocument: Symbol(
|
||||||
|
'FrameManager.FrameNavigatedWithinDocument'
|
||||||
|
),
|
||||||
|
ExecutionContextCreated: Symbol('FrameManager.ExecutionContextCreated'),
|
||||||
|
ExecutionContextDestroyed: Symbol('FrameManager.ExecutionContextDestroyed'),
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@ -197,14 +214,14 @@ export class FrameManager extends EventEmitter {
|
|||||||
const frame = this._frames.get(event.frameId);
|
const frame = this._frames.get(event.frameId);
|
||||||
if (!frame) return;
|
if (!frame) return;
|
||||||
frame._onLifecycleEvent(event.loaderId, event.name);
|
frame._onLifecycleEvent(event.loaderId, event.name);
|
||||||
this.emit(Events.FrameManager.LifecycleEvent, frame);
|
this.emit(FrameManagerEmittedEvents.LifecycleEvent, frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onFrameStoppedLoading(frameId: string): void {
|
_onFrameStoppedLoading(frameId: string): void {
|
||||||
const frame = this._frames.get(frameId);
|
const frame = this._frames.get(frameId);
|
||||||
if (!frame) return;
|
if (!frame) return;
|
||||||
frame._onLoadingStopped();
|
frame._onLoadingStopped();
|
||||||
this.emit(Events.FrameManager.LifecycleEvent, frame);
|
this.emit(FrameManagerEmittedEvents.LifecycleEvent, frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
_handleFrameTree(frameTree: Protocol.Page.FrameTree): void {
|
_handleFrameTree(frameTree: Protocol.Page.FrameTree): void {
|
||||||
@ -238,7 +255,7 @@ export class FrameManager extends EventEmitter {
|
|||||||
const parentFrame = this._frames.get(parentFrameId);
|
const parentFrame = this._frames.get(parentFrameId);
|
||||||
const frame = new Frame(this, parentFrame, frameId);
|
const frame = new Frame(this, parentFrame, frameId);
|
||||||
this._frames.set(frame._id, frame);
|
this._frames.set(frame._id, frame);
|
||||||
this.emit(Events.FrameManager.FrameAttached, frame);
|
this.emit(FrameManagerEmittedEvents.FrameAttached, frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onFrameNavigated(framePayload: Protocol.Page.Frame): void {
|
_onFrameNavigated(framePayload: Protocol.Page.Frame): void {
|
||||||
@ -274,7 +291,7 @@ export class FrameManager extends EventEmitter {
|
|||||||
// Update frame payload.
|
// Update frame payload.
|
||||||
frame._navigated(framePayload);
|
frame._navigated(framePayload);
|
||||||
|
|
||||||
this.emit(Events.FrameManager.FrameNavigated, frame);
|
this.emit(FrameManagerEmittedEvents.FrameNavigated, frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _ensureIsolatedWorld(name: string): Promise<void> {
|
async _ensureIsolatedWorld(name: string): Promise<void> {
|
||||||
@ -301,8 +318,8 @@ export class FrameManager extends EventEmitter {
|
|||||||
const frame = this._frames.get(frameId);
|
const frame = this._frames.get(frameId);
|
||||||
if (!frame) return;
|
if (!frame) return;
|
||||||
frame._navigatedWithinDocument(url);
|
frame._navigatedWithinDocument(url);
|
||||||
this.emit(Events.FrameManager.FrameNavigatedWithinDocument, frame);
|
this.emit(FrameManagerEmittedEvents.FrameNavigatedWithinDocument, frame);
|
||||||
this.emit(Events.FrameManager.FrameNavigated, frame);
|
this.emit(FrameManagerEmittedEvents.FrameNavigated, frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onFrameDetached(frameId: string): void {
|
_onFrameDetached(frameId: string): void {
|
||||||
@ -362,7 +379,7 @@ export class FrameManager extends EventEmitter {
|
|||||||
this._removeFramesRecursively(child);
|
this._removeFramesRecursively(child);
|
||||||
frame._detach();
|
frame._detach();
|
||||||
this._frames.delete(frame._id);
|
this._frames.delete(frame._id);
|
||||||
this.emit(Events.FrameManager.FrameDetached, frame);
|
this.emit(FrameManagerEmittedEvents.FrameDetached, frame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import { assert } from './assert';
|
|||||||
import { helper, PuppeteerEventListener } from './helper';
|
import { helper, PuppeteerEventListener } from './helper';
|
||||||
import { Events } from './Events';
|
import { Events } from './Events';
|
||||||
import { TimeoutError } from './Errors';
|
import { TimeoutError } from './Errors';
|
||||||
import { FrameManager, Frame } from './FrameManager';
|
import { FrameManager, Frame, FrameManagerEmittedEvents } from './FrameManager';
|
||||||
import { HTTPRequest } from './HTTPRequest';
|
import { HTTPRequest } from './HTTPRequest';
|
||||||
import { HTTPResponse } from './HTTPResponse';
|
import { HTTPResponse } from './HTTPResponse';
|
||||||
import { NetworkManagerEmittedEvents } from './NetworkManager';
|
import { NetworkManagerEmittedEvents } from './NetworkManager';
|
||||||
@ -103,17 +103,17 @@ export class LifecycleWatcher {
|
|||||||
),
|
),
|
||||||
helper.addEventListener(
|
helper.addEventListener(
|
||||||
this._frameManager,
|
this._frameManager,
|
||||||
Events.FrameManager.LifecycleEvent,
|
FrameManagerEmittedEvents.LifecycleEvent,
|
||||||
this._checkLifecycleComplete.bind(this)
|
this._checkLifecycleComplete.bind(this)
|
||||||
),
|
),
|
||||||
helper.addEventListener(
|
helper.addEventListener(
|
||||||
this._frameManager,
|
this._frameManager,
|
||||||
Events.FrameManager.FrameNavigatedWithinDocument,
|
FrameManagerEmittedEvents.FrameNavigatedWithinDocument,
|
||||||
this._navigatedWithinDocument.bind(this)
|
this._navigatedWithinDocument.bind(this)
|
||||||
),
|
),
|
||||||
helper.addEventListener(
|
helper.addEventListener(
|
||||||
this._frameManager,
|
this._frameManager,
|
||||||
Events.FrameManager.FrameDetached,
|
FrameManagerEmittedEvents.FrameDetached,
|
||||||
this._onFrameDetached.bind(this)
|
this._onFrameDetached.bind(this)
|
||||||
),
|
),
|
||||||
helper.addEventListener(
|
helper.addEventListener(
|
||||||
|
@ -22,7 +22,7 @@ import { Events } from './Events';
|
|||||||
import { Connection, CDPSession } from './Connection';
|
import { Connection, CDPSession } from './Connection';
|
||||||
import { Dialog } from './Dialog';
|
import { Dialog } from './Dialog';
|
||||||
import { EmulationManager } from './EmulationManager';
|
import { EmulationManager } from './EmulationManager';
|
||||||
import { Frame, FrameManager } from './FrameManager';
|
import { Frame, FrameManager, FrameManagerEmittedEvents } from './FrameManager';
|
||||||
import { Keyboard, Mouse, Touchscreen, MouseButton } from './Input';
|
import { Keyboard, Mouse, Touchscreen, MouseButton } from './Input';
|
||||||
import { Tracing } from './Tracing';
|
import { Tracing } from './Tracing';
|
||||||
import { assert } from './assert';
|
import { assert } from './assert';
|
||||||
@ -475,13 +475,13 @@ export class Page extends EventEmitter {
|
|||||||
this._workers.delete(event.sessionId);
|
this._workers.delete(event.sessionId);
|
||||||
});
|
});
|
||||||
|
|
||||||
this._frameManager.on(Events.FrameManager.FrameAttached, (event) =>
|
this._frameManager.on(FrameManagerEmittedEvents.FrameAttached, (event) =>
|
||||||
this.emit(PageEmittedEvents.FrameAttached, event)
|
this.emit(PageEmittedEvents.FrameAttached, event)
|
||||||
);
|
);
|
||||||
this._frameManager.on(Events.FrameManager.FrameDetached, (event) =>
|
this._frameManager.on(FrameManagerEmittedEvents.FrameDetached, (event) =>
|
||||||
this.emit(PageEmittedEvents.FrameDetached, event)
|
this.emit(PageEmittedEvents.FrameDetached, event)
|
||||||
);
|
);
|
||||||
this._frameManager.on(Events.FrameManager.FrameNavigated, (event) =>
|
this._frameManager.on(FrameManagerEmittedEvents.FrameNavigated, (event) =>
|
||||||
this.emit(PageEmittedEvents.FrameNavigated, event)
|
this.emit(PageEmittedEvents.FrameNavigated, event)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user