diff --git a/docs/api/puppeteer.commoneventemitter.addlistener.md b/docs/api/puppeteer.commoneventemitter.addlistener.md index e8282a856bd..7e2655b7a22 100644 --- a/docs/api/puppeteer.commoneventemitter.addlistener.md +++ b/docs/api/puppeteer.commoneventemitter.addlistener.md @@ -8,7 +8,7 @@ sidebar_label: CommonEventEmitter.addListener ```typescript interface CommonEventEmitter { - addListener(event: EventType, handler: Handler): CommonEventEmitter; + addListener(event: EventType, handler: Handler): this; } ``` @@ -21,4 +21,4 @@ interface CommonEventEmitter { **Returns:** -[CommonEventEmitter](./puppeteer.commoneventemitter.md) +this diff --git a/docs/api/puppeteer.commoneventemitter.off.md b/docs/api/puppeteer.commoneventemitter.off.md index 06c667d67c9..75b80adb965 100644 --- a/docs/api/puppeteer.commoneventemitter.off.md +++ b/docs/api/puppeteer.commoneventemitter.off.md @@ -8,7 +8,7 @@ sidebar_label: CommonEventEmitter.off ```typescript interface CommonEventEmitter { - off(event: EventType, handler: Handler): CommonEventEmitter; + off(event: EventType, handler: Handler): this; } ``` @@ -21,4 +21,4 @@ interface CommonEventEmitter { **Returns:** -[CommonEventEmitter](./puppeteer.commoneventemitter.md) +this diff --git a/docs/api/puppeteer.commoneventemitter.on.md b/docs/api/puppeteer.commoneventemitter.on.md index 0d4609e246a..2c257f84e1a 100644 --- a/docs/api/puppeteer.commoneventemitter.on.md +++ b/docs/api/puppeteer.commoneventemitter.on.md @@ -8,7 +8,7 @@ sidebar_label: CommonEventEmitter.on ```typescript interface CommonEventEmitter { - on(event: EventType, handler: Handler): CommonEventEmitter; + on(event: EventType, handler: Handler): this; } ``` @@ -21,4 +21,4 @@ interface CommonEventEmitter { **Returns:** -[CommonEventEmitter](./puppeteer.commoneventemitter.md) +this diff --git a/docs/api/puppeteer.commoneventemitter.once.md b/docs/api/puppeteer.commoneventemitter.once.md index d1595793064..73355af6f5c 100644 --- a/docs/api/puppeteer.commoneventemitter.once.md +++ b/docs/api/puppeteer.commoneventemitter.once.md @@ -8,7 +8,7 @@ sidebar_label: CommonEventEmitter.once ```typescript interface CommonEventEmitter { - once(event: EventType, handler: Handler): CommonEventEmitter; + once(event: EventType, handler: Handler): this; } ``` @@ -21,4 +21,4 @@ interface CommonEventEmitter { **Returns:** -[CommonEventEmitter](./puppeteer.commoneventemitter.md) +this diff --git a/docs/api/puppeteer.commoneventemitter.removealllisteners.md b/docs/api/puppeteer.commoneventemitter.removealllisteners.md index d944b40d22a..83b4cd7f34b 100644 --- a/docs/api/puppeteer.commoneventemitter.removealllisteners.md +++ b/docs/api/puppeteer.commoneventemitter.removealllisteners.md @@ -8,7 +8,7 @@ sidebar_label: CommonEventEmitter.removeAllListeners ```typescript interface CommonEventEmitter { - removeAllListeners(event?: EventType): CommonEventEmitter; + removeAllListeners(event?: EventType): this; } ``` @@ -20,4 +20,4 @@ interface CommonEventEmitter { **Returns:** -[CommonEventEmitter](./puppeteer.commoneventemitter.md) +this diff --git a/docs/api/puppeteer.commoneventemitter.removelistener.md b/docs/api/puppeteer.commoneventemitter.removelistener.md index 379c3ab234f..04ff12dffde 100644 --- a/docs/api/puppeteer.commoneventemitter.removelistener.md +++ b/docs/api/puppeteer.commoneventemitter.removelistener.md @@ -8,7 +8,7 @@ sidebar_label: CommonEventEmitter.removeListener ```typescript interface CommonEventEmitter { - removeListener(event: EventType, handler: Handler): CommonEventEmitter; + removeListener(event: EventType, handler: Handler): this; } ``` @@ -21,4 +21,4 @@ interface CommonEventEmitter { **Returns:** -[CommonEventEmitter](./puppeteer.commoneventemitter.md) +this diff --git a/docs/api/puppeteer.eventemitter.addlistener.md b/docs/api/puppeteer.eventemitter.addlistener.md index c139bd20f7d..1a53701c767 100644 --- a/docs/api/puppeteer.eventemitter.addlistener.md +++ b/docs/api/puppeteer.eventemitter.addlistener.md @@ -14,7 +14,7 @@ Add an event listener. ```typescript class EventEmitter { - addListener(event: EventType, handler: Handler): EventEmitter; + addListener(event: EventType, handler: Handler): this; } ``` @@ -27,4 +27,4 @@ class EventEmitter { **Returns:** -[EventEmitter](./puppeteer.eventemitter.md) +this diff --git a/docs/api/puppeteer.eventemitter.off.md b/docs/api/puppeteer.eventemitter.off.md index 98f6eac89e9..107082b191d 100644 --- a/docs/api/puppeteer.eventemitter.off.md +++ b/docs/api/puppeteer.eventemitter.off.md @@ -10,7 +10,7 @@ Remove an event listener from firing. ```typescript class EventEmitter { - off(event: EventType, handler: Handler): EventEmitter; + off(event: EventType, handler: Handler): this; } ``` @@ -23,6 +23,6 @@ class EventEmitter { **Returns:** -[EventEmitter](./puppeteer.eventemitter.md) +this `this` to enable you to chain method calls. diff --git a/docs/api/puppeteer.eventemitter.on.md b/docs/api/puppeteer.eventemitter.on.md index e1fee2a2ae7..f04ea8d5e09 100644 --- a/docs/api/puppeteer.eventemitter.on.md +++ b/docs/api/puppeteer.eventemitter.on.md @@ -10,7 +10,7 @@ Bind an event listener to fire when an event occurs. ```typescript class EventEmitter { - on(event: EventType, handler: Handler): EventEmitter; + on(event: EventType, handler: Handler): this; } ``` @@ -23,6 +23,6 @@ class EventEmitter { **Returns:** -[EventEmitter](./puppeteer.eventemitter.md) +this `this` to enable you to chain method calls. diff --git a/docs/api/puppeteer.eventemitter.once.md b/docs/api/puppeteer.eventemitter.once.md index 94054eb2c2d..5d12b896064 100644 --- a/docs/api/puppeteer.eventemitter.once.md +++ b/docs/api/puppeteer.eventemitter.once.md @@ -10,7 +10,7 @@ Like `on` but the listener will only be fired once and then it will be removed. ```typescript class EventEmitter { - once(event: EventType, handler: Handler): EventEmitter; + once(event: EventType, handler: Handler): this; } ``` @@ -23,6 +23,6 @@ class EventEmitter { **Returns:** -[EventEmitter](./puppeteer.eventemitter.md) +this `this` to enable you to chain method calls. diff --git a/docs/api/puppeteer.eventemitter.removealllisteners.md b/docs/api/puppeteer.eventemitter.removealllisteners.md index a339bbdd42e..1badbe777d9 100644 --- a/docs/api/puppeteer.eventemitter.removealllisteners.md +++ b/docs/api/puppeteer.eventemitter.removealllisteners.md @@ -10,7 +10,7 @@ Removes all listeners. If given an event argument, it will remove only listeners ```typescript class EventEmitter { - removeAllListeners(event?: EventType): EventEmitter; + removeAllListeners(event?: EventType): this; } ``` @@ -22,6 +22,6 @@ class EventEmitter { **Returns:** -[EventEmitter](./puppeteer.eventemitter.md) +this `this` to enable you to chain method calls. diff --git a/docs/api/puppeteer.eventemitter.removelistener.md b/docs/api/puppeteer.eventemitter.removelistener.md index 76e25571e3a..72e5ac7bd99 100644 --- a/docs/api/puppeteer.eventemitter.removelistener.md +++ b/docs/api/puppeteer.eventemitter.removelistener.md @@ -14,7 +14,7 @@ Remove an event listener. ```typescript class EventEmitter { - removeListener(event: EventType, handler: Handler): EventEmitter; + removeListener(event: EventType, handler: Handler): this; } ``` @@ -27,4 +27,4 @@ class EventEmitter { **Returns:** -[EventEmitter](./puppeteer.eventemitter.md) +this diff --git a/docs/api/puppeteer.page.off.md b/docs/api/puppeteer.page.off.md index 588f27c23b7..dadfa5968f5 100644 --- a/docs/api/puppeteer.page.off.md +++ b/docs/api/puppeteer.page.off.md @@ -11,7 +11,7 @@ class Page { off( eventName: K, handler: (event: PageEventObject[K]) => void - ): EventEmitter; + ): this; } ``` @@ -24,4 +24,4 @@ class Page { **Returns:** -[EventEmitter](./puppeteer.eventemitter.md) +this diff --git a/docs/api/puppeteer.page.on.md b/docs/api/puppeteer.page.on.md index a5d880d05d6..c2c8da12ad7 100644 --- a/docs/api/puppeteer.page.on.md +++ b/docs/api/puppeteer.page.on.md @@ -19,7 +19,7 @@ class Page { on( eventName: K, handler: (event: PageEventObject[K]) => void - ): EventEmitter; + ): this; } ``` @@ -32,4 +32,4 @@ class Page { **Returns:** -[EventEmitter](./puppeteer.eventemitter.md) +this diff --git a/docs/api/puppeteer.page.once.md b/docs/api/puppeteer.page.once.md index af45198df93..3cdb2079a67 100644 --- a/docs/api/puppeteer.page.once.md +++ b/docs/api/puppeteer.page.once.md @@ -11,7 +11,7 @@ class Page { once( eventName: K, handler: (event: PageEventObject[K]) => void - ): EventEmitter; + ): this; } ``` @@ -24,4 +24,4 @@ class Page { **Returns:** -[EventEmitter](./puppeteer.eventemitter.md) +this diff --git a/packages/puppeteer-core/src/api/Locator.ts b/packages/puppeteer-core/src/api/Locator.ts index b26815cc1e6..8a2470ecd56 100644 --- a/packages/puppeteer-core/src/api/Locator.ts +++ b/packages/puppeteer-core/src/api/Locator.ts @@ -109,22 +109,22 @@ export class Locator extends EventEmitter { override on( eventName: K, handler: (event: LocatorEventObject[K]) => void - ): Locator { - return super.on(eventName, handler) as Locator; + ): this { + return super.on(eventName, handler); } override once( eventName: K, handler: (event: LocatorEventObject[K]) => void - ): Locator { - return super.once(eventName, handler) as Locator; + ): this { + return super.once(eventName, handler); } override off( eventName: K, handler: (event: LocatorEventObject[K]) => void - ): Locator { - return super.off(eventName, handler) as Locator; + ): this { + return super.off(eventName, handler); } /** diff --git a/packages/puppeteer-core/src/api/Page.ts b/packages/puppeteer-core/src/api/Page.ts index f60b2da0044..dd4c6a054dd 100644 --- a/packages/puppeteer-core/src/api/Page.ts +++ b/packages/puppeteer-core/src/api/Page.ts @@ -480,7 +480,7 @@ export class Page extends EventEmitter { override on( eventName: K, handler: (event: PageEventObject[K]) => void - ): EventEmitter { + ): this { if (eventName === 'request') { const wrap = this.#handlerMap.get(handler) || @@ -500,7 +500,7 @@ export class Page extends EventEmitter { override once( eventName: K, handler: (event: PageEventObject[K]) => void - ): EventEmitter { + ): this { // Note: this method only exists to define the types; we delegate the impl // to EventEmitter. return super.once(eventName, handler); @@ -509,7 +509,7 @@ export class Page extends EventEmitter { override off( eventName: K, handler: (event: PageEventObject[K]) => void - ): EventEmitter { + ): this { if (eventName === 'request') { handler = this.#handlerMap.get(handler) || handler; } diff --git a/packages/puppeteer-core/src/common/EventEmitter.ts b/packages/puppeteer-core/src/common/EventEmitter.ts index 41001a15929..89faab94b6b 100644 --- a/packages/puppeteer-core/src/common/EventEmitter.ts +++ b/packages/puppeteer-core/src/common/EventEmitter.ts @@ -29,19 +29,19 @@ export type Handler = (event: T) => void; * @public */ export interface CommonEventEmitter { - on(event: EventType, handler: Handler): CommonEventEmitter; - off(event: EventType, handler: Handler): CommonEventEmitter; + on(event: EventType, handler: Handler): this; + off(event: EventType, handler: Handler): this; /* To maintain parity with the built in NodeJS event emitter which uses removeListener * rather than `off`. * If you're implementing new code you should use `off`. */ - addListener(event: EventType, handler: Handler): CommonEventEmitter; - removeListener(event: EventType, handler: Handler): CommonEventEmitter; + addListener(event: EventType, handler: Handler): this; + removeListener(event: EventType, handler: Handler): this; emit(event: EventType, eventData?: unknown): boolean; - once(event: EventType, handler: Handler): CommonEventEmitter; + once(event: EventType, handler: Handler): this; listenerCount(event: string): number; - removeAllListeners(event?: EventType): CommonEventEmitter; + removeAllListeners(event?: EventType): this; } /** @@ -73,7 +73,7 @@ export class EventEmitter implements CommonEventEmitter { * @param handler - the function to be called when the event occurs. * @returns `this` to enable you to chain method calls. */ - on(event: EventType, handler: Handler): EventEmitter { + on(event: EventType, handler: Handler): this { this.emitter.on(event, handler); return this; } @@ -84,7 +84,7 @@ export class EventEmitter implements CommonEventEmitter { * @param handler - the function that should be removed. * @returns `this` to enable you to chain method calls. */ - off(event: EventType, handler: Handler): EventEmitter { + off(event: EventType, handler: Handler): this { this.emitter.off(event, handler); return this; } @@ -93,7 +93,7 @@ export class EventEmitter implements CommonEventEmitter { * Remove an event listener. * @deprecated please use {@link EventEmitter.off} instead. */ - removeListener(event: EventType, handler: Handler): EventEmitter { + removeListener(event: EventType, handler: Handler): this { this.off(event, handler); return this; } @@ -102,7 +102,7 @@ export class EventEmitter implements CommonEventEmitter { * Add an event listener. * @deprecated please use {@link EventEmitter.on} instead. */ - addListener(event: EventType, handler: Handler): EventEmitter { + addListener(event: EventType, handler: Handler): this { this.on(event, handler); return this; } @@ -125,7 +125,7 @@ export class EventEmitter implements CommonEventEmitter { * @param handler - the handler function to run when the event occurs * @returns `this` to enable you to chain method calls. */ - once(event: EventType, handler: Handler): EventEmitter { + once(event: EventType, handler: Handler): this { const onceHandler: Handler = eventData => { handler(eventData); this.off(event, onceHandler); @@ -150,7 +150,7 @@ export class EventEmitter implements CommonEventEmitter { * @param event - the event to remove listeners for. * @returns `this` to enable you to chain method calls. */ - removeAllListeners(event?: EventType): EventEmitter { + removeAllListeners(event?: EventType): this { if (event) { this.eventsMap.delete(event); } else { diff --git a/packages/puppeteer-core/src/common/bidi/BidiOverCDP.ts b/packages/puppeteer-core/src/common/bidi/BidiOverCDP.ts index 82381ae4a8e..62166fd9202 100644 --- a/packages/puppeteer-core/src/common/bidi/BidiOverCDP.ts +++ b/packages/puppeteer-core/src/common/bidi/BidiOverCDP.ts @@ -20,7 +20,7 @@ import type {ProtocolMapping} from 'devtools-protocol/types/protocol-mapping.js' import {CDPSession, Connection as CDPPPtrConnection} from '../Connection.js'; import {TargetCloseError} from '../Errors.js'; -import {Handler} from '../EventEmitter.js'; +import {EventEmitter, Handler} from '../EventEmitter.js'; import {Connection as BidiPPtrConnection} from './Connection.js'; @@ -107,7 +107,7 @@ class CDPConnectionAdapter { * * @internal */ -class CDPClientAdapter> +class CDPClientAdapter> extends BidiMapper.EventEmitter implements BidiMapper.CdpClient {