mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
docs(README): Add's page.removeListener to Page class examples (#2122)
This patch adds `page.removeListener` to Page class examples
This commit is contained in:
parent
554bd59588
commit
552be1ae87
13
docs/api.md
13
docs/api.md
@ -501,13 +501,24 @@ puppeteer.launch().then(async browser => {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
The Page class emits various events (described below) which can be handled using any of Node's native [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter) methods, such as `on` or `once`.
|
The Page class emits various events (described below) which can be handled using any of Node's native [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter) methods, such as `on`, `once` or `removeListener`.
|
||||||
|
|
||||||
This example logs a message for a single page `load` event:
|
This example logs a message for a single page `load` event:
|
||||||
```js
|
```js
|
||||||
page.once('load', () => console.log('Page loaded!'));
|
page.once('load', () => console.log('Page loaded!'));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To unsubscribe from events use the `removeListener` method:
|
||||||
|
|
||||||
|
```js
|
||||||
|
function logRequest(interceptedRequest) {
|
||||||
|
console.log('A request was made:', interceptedRequest.url());
|
||||||
|
}
|
||||||
|
page.on('request', logRequest);
|
||||||
|
// Sometime later...
|
||||||
|
page.removeListener('request', logRequest);
|
||||||
|
```
|
||||||
|
|
||||||
#### event: 'console'
|
#### event: 'console'
|
||||||
- <[ConsoleMessage]>
|
- <[ConsoleMessage]>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user