puppeteer/website/versioned_docs/version-21.9.0/api/puppeteer.eventemitter.md
release-please[bot] d57b1044f2
chore: release main (#11744)
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
2024-01-24 13:53:06 +00:00

2.6 KiB

sidebar_label
EventEmitter

EventEmitter class

The EventEmitter class that many Puppeteer classes extend.

Signature:

export declare class EventEmitter<Events extends Record<EventType, unknown>> implements CommonEventEmitter<EventsWithWildcard<Events>>

Implements: CommonEventEmitter<EventsWithWildcard<Events>>

Remarks

This allows you to listen to events that Puppeteer classes fire and act accordingly. Therefore you'll mostly use on and off to bind and unbind to event listeners.

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the EventEmitter class.

Methods

Method Modifiers Description
addListener Add an event listener.
emit Emit an event and call any associated listeners.
listenerCount Gets the number of listeners for a given event.
off Remove an event listener from firing.
on Bind an event listener to fire when an event occurs.
once Like on but the listener will only be fired once and then it will be removed.
removeAllListeners Removes all listeners. If given an event argument, it will remove only listeners for that event.
removeListener Remove an event listener.