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:
Joel Griffith 2018-03-13 09:25:25 -07:00 committed by Andrey Lushnikov
parent 554bd59588
commit 552be1ae87

View File

@ -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:
```js
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'
- <[ConsoleMessage]>