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.
|
* @returns Promise which resolves to an array of all open pages.
|
||||||
* Non visible pages, such as `"background_page"`, will not be listed here.
|
* 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[]> {
|
override async pages(): Promise<Page[]> {
|
||||||
const pages = await Promise.all(
|
const pages = await Promise.all(
|
||||||
|
@ -152,54 +152,38 @@ export class CDPPage extends Page {
|
|||||||
#frameManagerHandlers = new Map<symbol, Handler<any>>([
|
#frameManagerHandlers = new Map<symbol, Handler<any>>([
|
||||||
[
|
[
|
||||||
FrameManagerEmittedEvents.FrameAttached,
|
FrameManagerEmittedEvents.FrameAttached,
|
||||||
event => {
|
this.emit.bind(this, PageEmittedEvents.FrameAttached),
|
||||||
return this.emit(PageEmittedEvents.FrameAttached, event);
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
FrameManagerEmittedEvents.FrameDetached,
|
FrameManagerEmittedEvents.FrameDetached,
|
||||||
event => {
|
this.emit.bind(this, PageEmittedEvents.FrameDetached),
|
||||||
return this.emit(PageEmittedEvents.FrameDetached, event);
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
FrameManagerEmittedEvents.FrameNavigated,
|
FrameManagerEmittedEvents.FrameNavigated,
|
||||||
event => {
|
this.emit.bind(this, PageEmittedEvents.FrameNavigated),
|
||||||
return this.emit(PageEmittedEvents.FrameNavigated, event);
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
#networkManagerHandlers = new Map<symbol, Handler<any>>([
|
#networkManagerHandlers = new Map<symbol, Handler<any>>([
|
||||||
[
|
[
|
||||||
NetworkManagerEmittedEvents.Request,
|
NetworkManagerEmittedEvents.Request,
|
||||||
event => {
|
this.emit.bind(this, PageEmittedEvents.Request),
|
||||||
return this.emit(PageEmittedEvents.Request, event);
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
NetworkManagerEmittedEvents.RequestServedFromCache,
|
NetworkManagerEmittedEvents.RequestServedFromCache,
|
||||||
event => {
|
this.emit.bind(this, PageEmittedEvents.RequestServedFromCache),
|
||||||
return this.emit(PageEmittedEvents.RequestServedFromCache, event);
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
NetworkManagerEmittedEvents.Response,
|
NetworkManagerEmittedEvents.Response,
|
||||||
event => {
|
this.emit.bind(this, PageEmittedEvents.Response),
|
||||||
return this.emit(PageEmittedEvents.Response, event);
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
NetworkManagerEmittedEvents.RequestFailed,
|
NetworkManagerEmittedEvents.RequestFailed,
|
||||||
event => {
|
this.emit.bind(this, PageEmittedEvents.RequestFailed),
|
||||||
return this.emit(PageEmittedEvents.RequestFailed, event);
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
NetworkManagerEmittedEvents.RequestFinished,
|
NetworkManagerEmittedEvents.RequestFinished,
|
||||||
event => {
|
this.emit.bind(this, PageEmittedEvents.RequestFinished),
|
||||||
return this.emit(PageEmittedEvents.RequestFinished, event);
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -214,70 +198,17 @@ export class CDPPage extends Page {
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Page.domContentEventFired',
|
'Page.domContentEventFired',
|
||||||
() => {
|
this.emit.bind(this, PageEmittedEvents.DOMContentLoaded),
|
||||||
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);
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
|
['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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#handleException(exceptionDetails: Protocol.Runtime.ExceptionDetails): void {
|
#handleException(exception: Protocol.Runtime.ExceptionThrownEvent): void {
|
||||||
this.emit(PageEmittedEvents.PageError, createClientError(exceptionDetails));
|
this.emit(
|
||||||
|
PageEmittedEvents.PageError,
|
||||||
|
createClientError(exception.exceptionDetails)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async #onConsoleAPI(
|
async #onConsoleAPI(
|
||||||
|
@ -38,7 +38,7 @@ export type ConsoleAPICalledCallback = (
|
|||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export type ExceptionThrownCallback = (
|
export type ExceptionThrownCallback = (
|
||||||
details: Protocol.Runtime.ExceptionDetails
|
event: Protocol.Runtime.ExceptionThrownEvent
|
||||||
) => void;
|
) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,7 +69,6 @@ export type ExceptionThrownCallback = (
|
|||||||
*/
|
*/
|
||||||
export class WebWorker extends EventEmitter {
|
export class WebWorker extends EventEmitter {
|
||||||
#executionContext = Deferred.create<ExecutionContext>();
|
#executionContext = Deferred.create<ExecutionContext>();
|
||||||
|
|
||||||
#client: CDPSession;
|
#client: CDPSession;
|
||||||
#url: string;
|
#url: string;
|
||||||
|
|
||||||
@ -104,9 +103,7 @@ export class WebWorker extends EventEmitter {
|
|||||||
debugError(err);
|
debugError(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.#client.on('Runtime.exceptionThrown', exception => {
|
this.#client.on('Runtime.exceptionThrown', exceptionThrown);
|
||||||
return exceptionThrown(exception.exceptionDetails);
|
|
||||||
});
|
|
||||||
|
|
||||||
// This might fail if the target is closed before we receive all execution contexts.
|
// This might fail if the target is closed before we receive all execution contexts.
|
||||||
this.#client.send('Runtime.enable').catch(debugError);
|
this.#client.send('Runtime.enable').catch(debugError);
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
export * from './Accessibility.js';
|
export * from './Accessibility.js';
|
||||||
export * from './AriaQueryHandler.js';
|
export * from './AriaQueryHandler.js';
|
||||||
|
export * from './Binding.js';
|
||||||
export * from './Browser.js';
|
export * from './Browser.js';
|
||||||
export * from './BrowserConnector.js';
|
export * from './BrowserConnector.js';
|
||||||
export * from './BrowserWebSocketTransport.js';
|
export * from './BrowserWebSocketTransport.js';
|
||||||
|
Loading…
Reference in New Issue
Block a user