mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
refactor: event maps and docs warnings (#10800)
This commit is contained in:
parent
b9744b2c95
commit
3ffafc67d5
@ -610,7 +610,7 @@ export class CDPBrowserContext extends BrowserContext {
|
||||
*
|
||||
* @returns Promise which resolves to an array of all open pages.
|
||||
* Non visible pages, such as `"background_page"`, will not be listed here.
|
||||
* You can find them using {@link CDPTarget.page | the target page}.
|
||||
* You can find them using {@link Target.page | the target page}.
|
||||
*/
|
||||
override async pages(): Promise<Page[]> {
|
||||
const pages = await Promise.all(
|
||||
|
@ -152,54 +152,38 @@ export class CDPPage extends Page {
|
||||
#frameManagerHandlers = new Map<symbol, Handler<any>>([
|
||||
[
|
||||
FrameManagerEmittedEvents.FrameAttached,
|
||||
event => {
|
||||
return this.emit(PageEmittedEvents.FrameAttached, event);
|
||||
},
|
||||
this.emit.bind(this, PageEmittedEvents.FrameAttached),
|
||||
],
|
||||
[
|
||||
FrameManagerEmittedEvents.FrameDetached,
|
||||
event => {
|
||||
return this.emit(PageEmittedEvents.FrameDetached, event);
|
||||
},
|
||||
this.emit.bind(this, PageEmittedEvents.FrameDetached),
|
||||
],
|
||||
[
|
||||
FrameManagerEmittedEvents.FrameNavigated,
|
||||
event => {
|
||||
return this.emit(PageEmittedEvents.FrameNavigated, event);
|
||||
},
|
||||
this.emit.bind(this, PageEmittedEvents.FrameNavigated),
|
||||
],
|
||||
]);
|
||||
|
||||
#networkManagerHandlers = new Map<symbol, Handler<any>>([
|
||||
[
|
||||
NetworkManagerEmittedEvents.Request,
|
||||
event => {
|
||||
return this.emit(PageEmittedEvents.Request, event);
|
||||
},
|
||||
this.emit.bind(this, PageEmittedEvents.Request),
|
||||
],
|
||||
[
|
||||
NetworkManagerEmittedEvents.RequestServedFromCache,
|
||||
event => {
|
||||
return this.emit(PageEmittedEvents.RequestServedFromCache, event);
|
||||
},
|
||||
this.emit.bind(this, PageEmittedEvents.RequestServedFromCache),
|
||||
],
|
||||
[
|
||||
NetworkManagerEmittedEvents.Response,
|
||||
event => {
|
||||
return this.emit(PageEmittedEvents.Response, event);
|
||||
},
|
||||
this.emit.bind(this, PageEmittedEvents.Response),
|
||||
],
|
||||
[
|
||||
NetworkManagerEmittedEvents.RequestFailed,
|
||||
event => {
|
||||
return this.emit(PageEmittedEvents.RequestFailed, event);
|
||||
},
|
||||
this.emit.bind(this, PageEmittedEvents.RequestFailed),
|
||||
],
|
||||
[
|
||||
NetworkManagerEmittedEvents.RequestFinished,
|
||||
event => {
|
||||
return this.emit(PageEmittedEvents.RequestFinished, event);
|
||||
},
|
||||
this.emit.bind(this, PageEmittedEvents.RequestFinished),
|
||||
],
|
||||
]);
|
||||
|
||||
@ -214,70 +198,17 @@ export class CDPPage extends Page {
|
||||
],
|
||||
[
|
||||
'Page.domContentEventFired',
|
||||
() => {
|
||||
return this.emit(PageEmittedEvents.DOMContentLoaded);
|
||||
},
|
||||
],
|
||||
[
|
||||
'Page.loadEventFired',
|
||||
() => {
|
||||
return this.emit(PageEmittedEvents.Load);
|
||||
},
|
||||
],
|
||||
[
|
||||
'Page.loadEventFired',
|
||||
() => {
|
||||
return this.emit(PageEmittedEvents.Load);
|
||||
},
|
||||
],
|
||||
[
|
||||
'Runtime.consoleAPICalled',
|
||||
event => {
|
||||
return this.#onConsoleAPI(event);
|
||||
},
|
||||
],
|
||||
[
|
||||
'Runtime.bindingCalled',
|
||||
event => {
|
||||
return this.#onBindingCalled(event);
|
||||
},
|
||||
],
|
||||
[
|
||||
'Page.javascriptDialogOpening',
|
||||
event => {
|
||||
return this.#onDialog(event);
|
||||
},
|
||||
],
|
||||
[
|
||||
'Runtime.exceptionThrown',
|
||||
exception => {
|
||||
return this.#handleException(exception.exceptionDetails);
|
||||
},
|
||||
],
|
||||
[
|
||||
'Inspector.targetCrashed',
|
||||
() => {
|
||||
return this.#onTargetCrashed();
|
||||
},
|
||||
],
|
||||
[
|
||||
'Performance.metrics',
|
||||
event => {
|
||||
return this.#emitMetrics(event);
|
||||
},
|
||||
],
|
||||
[
|
||||
'Log.entryAdded',
|
||||
event => {
|
||||
return this.#onLogEntryAdded(event);
|
||||
},
|
||||
],
|
||||
[
|
||||
'Page.fileChooserOpened',
|
||||
event => {
|
||||
return this.#onFileChooser(event);
|
||||
},
|
||||
this.emit.bind(this, PageEmittedEvents.DOMContentLoaded),
|
||||
],
|
||||
['Page.loadEventFired', this.emit.bind(this, PageEmittedEvents.Load)],
|
||||
['Runtime.consoleAPICalled', this.#onConsoleAPI.bind(this)],
|
||||
['Runtime.bindingCalled', this.#onBindingCalled.bind(this)],
|
||||
['Page.javascriptDialogOpening', this.#onDialog.bind(this)],
|
||||
['Runtime.exceptionThrown', this.#handleException.bind(this)],
|
||||
['Inspector.targetCrashed', this.#onTargetCrashed.bind(this)],
|
||||
['Performance.metrics', this.#emitMetrics.bind(this)],
|
||||
['Log.entryAdded', this.#onLogEntryAdded.bind(this)],
|
||||
['Page.fileChooserOpened', this.#onFileChooser.bind(this)],
|
||||
]);
|
||||
|
||||
/**
|
||||
@ -802,8 +733,11 @@ export class CDPPage extends Page {
|
||||
return result;
|
||||
}
|
||||
|
||||
#handleException(exceptionDetails: Protocol.Runtime.ExceptionDetails): void {
|
||||
this.emit(PageEmittedEvents.PageError, createClientError(exceptionDetails));
|
||||
#handleException(exception: Protocol.Runtime.ExceptionThrownEvent): void {
|
||||
this.emit(
|
||||
PageEmittedEvents.PageError,
|
||||
createClientError(exception.exceptionDetails)
|
||||
);
|
||||
}
|
||||
|
||||
async #onConsoleAPI(
|
||||
|
@ -38,7 +38,7 @@ export type ConsoleAPICalledCallback = (
|
||||
* @internal
|
||||
*/
|
||||
export type ExceptionThrownCallback = (
|
||||
details: Protocol.Runtime.ExceptionDetails
|
||||
event: Protocol.Runtime.ExceptionThrownEvent
|
||||
) => void;
|
||||
|
||||
/**
|
||||
@ -69,7 +69,6 @@ export type ExceptionThrownCallback = (
|
||||
*/
|
||||
export class WebWorker extends EventEmitter {
|
||||
#executionContext = Deferred.create<ExecutionContext>();
|
||||
|
||||
#client: CDPSession;
|
||||
#url: string;
|
||||
|
||||
@ -104,9 +103,7 @@ export class WebWorker extends EventEmitter {
|
||||
debugError(err);
|
||||
}
|
||||
});
|
||||
this.#client.on('Runtime.exceptionThrown', exception => {
|
||||
return exceptionThrown(exception.exceptionDetails);
|
||||
});
|
||||
this.#client.on('Runtime.exceptionThrown', exceptionThrown);
|
||||
|
||||
// This might fail if the target is closed before we receive all execution contexts.
|
||||
this.#client.send('Runtime.enable').catch(debugError);
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
export * from './Accessibility.js';
|
||||
export * from './AriaQueryHandler.js';
|
||||
export * from './Binding.js';
|
||||
export * from './Browser.js';
|
||||
export * from './BrowserConnector.js';
|
||||
export * from './BrowserWebSocketTransport.js';
|
||||
|
Loading…
Reference in New Issue
Block a user