puppeteer/docs/api/puppeteer.eventemitter.md

33 lines
2.3 KiB
Markdown
Raw Normal View History

2022-07-05 13:41:43 +00:00
---
sidebar_label: EventEmitter
---
# EventEmitter class
The EventEmitter class that many Puppeteer classes extend.
#### Signature:
2022-07-05 13:41:43 +00:00
```typescript
2023-09-13 13:47:55 +00:00
export declare class EventEmitter<Events extends Record<EventType, unknown>> implements CommonEventEmitter<EventsWithWildcard<Events>>
2022-07-05 13:41:43 +00:00
```
2023-09-13 13:47:55 +00:00
**Implements:** [CommonEventEmitter](./puppeteer.commoneventemitter.md)&lt;[EventsWithWildcard](./puppeteer.eventswithwildcard.md)&lt;Events&gt;&gt;
2022-07-05 13:41:43 +00:00
## Remarks
This allows you to listen to events that Puppeteer classes fire and act accordingly. Therefore you'll mostly use [on](./puppeteer.eventemitter.on.md) and [off](./puppeteer.eventemitter.off.md) 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 |
| -------------------------------------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------ |
| [emit(type, event)](./puppeteer.eventemitter.emit.md) | | Emit an event and call any associated listeners. |
| [listenerCount(type)](./puppeteer.eventemitter.listenercount.md) | | Gets the number of listeners for a given event. |
| [off(type, handler)](./puppeteer.eventemitter.off.md) | | Remove an event listener from firing. |
| [on(type, handler)](./puppeteer.eventemitter.on.md) | | Bind an event listener to fire when an event occurs. |
| [once(type, handler)](./puppeteer.eventemitter.once.md) | | Like <code>on</code> but the listener will only be fired once and then it will be removed. |
| [removeAllListeners(type)](./puppeteer.eventemitter.removealllisteners.md) | | Removes all listeners. If given an event argument, it will remove only listeners for that event. |