| 
									
										
										
										
											2020-06-22 16:53:56 -07:00
										 |  |  | # Verification
 | 
					
						
							| 
									
										
										
										
											2020-04-20 16:56:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-11 09:54:03 -07:00
										 |  |  | <!-- GEN:toc-top-level --> | 
					
						
							| 
									
										
										
										
											2020-06-22 16:53:56 -07:00
										 |  |  | - [Screenshots](#screenshots) | 
					
						
							|  |  |  | - [Console logs](#console-logs) | 
					
						
							|  |  |  | - [Page errors](#page-errors) | 
					
						
							| 
									
										
										
										
											2020-04-20 17:17:10 -07:00
										 |  |  | - [Page events](#page-events) | 
					
						
							| 
									
										
										
										
											2020-05-11 09:54:03 -07:00
										 |  |  | <!-- GEN:stop --> | 
					
						
							| 
									
										
										
										
											2020-04-20 16:56:46 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | <br/> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-22 16:53:56 -07:00
										 |  |  | ## Screenshots
 | 
					
						
							| 
									
										
										
										
											2020-04-20 16:56:46 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							| 
									
										
										
										
											2020-05-02 17:21:46 -07:00
										 |  |  | // Save to file | 
					
						
							| 
									
										
										
										
											2020-04-20 17:17:10 -07:00
										 |  |  | await page.screenshot({path: 'screenshot.png'}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-02 17:21:46 -07:00
										 |  |  | // Capture full page | 
					
						
							| 
									
										
										
										
											2020-04-20 17:17:10 -07:00
										 |  |  | await page.screenshot({path: 'screenshot.png', fullPage: true}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-02 17:21:46 -07:00
										 |  |  | // Capture into buffer | 
					
						
							| 
									
										
										
										
											2020-04-20 17:17:10 -07:00
										 |  |  | const buffer = await page.screenshot(); | 
					
						
							|  |  |  | console.log(buffer.toString('base64')); | 
					
						
							| 
									
										
										
										
											2020-04-20 16:56:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-02 17:21:46 -07:00
										 |  |  | // Capture given element | 
					
						
							|  |  |  | const elementHandle = await page.$('.header'); | 
					
						
							|  |  |  | await elementHandle.screenshot({ path: 'screenshot.png' }); | 
					
						
							| 
									
										
										
										
											2020-05-03 16:59:41 +02:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2020-04-20 16:56:46 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #### API reference
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - [page.screenshot([options])](./api.md#pagescreenshotoptions) | 
					
						
							| 
									
										
										
										
											2020-04-20 17:17:10 -07:00
										 |  |  | - [elementHandle.screenshot([options])](./api.md#elementhandlescreenshotoptions) | 
					
						
							| 
									
										
										
										
											2020-04-20 16:56:46 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | <br/> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-22 16:53:56 -07:00
										 |  |  | ## Console logs
 | 
					
						
							| 
									
										
										
										
											2020-04-20 16:56:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-23 19:34:18 -07:00
										 |  |  | Console messages logged in the page can be brought into the Node.js context. | 
					
						
							| 
									
										
										
										
											2020-04-20 16:56:46 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							| 
									
										
										
										
											2020-06-23 19:34:18 -07:00
										 |  |  | // Listen for all console logs | 
					
						
							|  |  |  | page.on('console', msg => console.log(msg.text())) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Listen for all console events and handle errors | 
					
						
							| 
									
										
										
										
											2020-04-20 17:17:10 -07:00
										 |  |  | page.on('console', msg => { | 
					
						
							| 
									
										
										
										
											2020-06-23 19:34:18 -07:00
										 |  |  |   if (msg.type() === 'error') | 
					
						
							|  |  |  |     console.log(`Error text: "${msg.text()}"`); | 
					
						
							| 
									
										
										
										
											2020-04-20 17:17:10 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-06-23 19:34:18 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Get the next console log | 
					
						
							|  |  |  | const [msg] = await Promise.all([ | 
					
						
							|  |  |  |   page.waitForEvent('console'), | 
					
						
							|  |  |  |   // Issue console.log inside the page | 
					
						
							|  |  |  |   page.evaluate(() => { | 
					
						
							|  |  |  |     console.log('hello', 42, {foo: 'bar'}); | 
					
						
							|  |  |  |   }), | 
					
						
							|  |  |  | ]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Deconstruct console log arguments | 
					
						
							|  |  |  | await msg.args[0].jsonValue() // hello | 
					
						
							|  |  |  | await msg.args[1].jsonValue() // 42 | 
					
						
							| 
									
										
										
										
											2020-04-20 16:56:46 -07:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #### API reference
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-21 11:28:08 -07:00
										 |  |  | - [class: ConsoleMessage](./api.md#class-consolemessage) | 
					
						
							| 
									
										
										
										
											2020-04-20 17:17:10 -07:00
										 |  |  | - [class: Page](./api.md#class-page) | 
					
						
							|  |  |  | - [event: 'console'](./api.md#event-console) | 
					
						
							| 
									
										
										
										
											2020-04-20 16:56:46 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | <br/> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-22 16:53:56 -07:00
										 |  |  | ## Page errors
 | 
					
						
							| 
									
										
										
										
											2020-04-20 16:56:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-22 16:53:56 -07:00
										 |  |  | Listen for uncaught exceptions in the page with the `pagerror` event. | 
					
						
							| 
									
										
										
										
											2020-04-20 17:17:10 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-20 16:56:46 -07:00
										 |  |  | ```js | 
					
						
							| 
									
										
										
										
											2020-04-20 17:17:10 -07:00
										 |  |  | // Log all uncaught errors to the terminal | 
					
						
							|  |  |  | page.on('pageerror', exception => { | 
					
						
							|  |  |  |   console.log(`Uncaught exception: "${exception}"`); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Navigate to a page with an exception. | 
					
						
							|  |  |  | await page.goto('data:text/html,<script>throw new Error("Test")</script>'); | 
					
						
							| 
									
										
										
										
											2020-04-20 16:56:46 -07:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #### API reference
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-22 16:53:56 -07:00
										 |  |  | - [class: Page](./api.md#class-page) | 
					
						
							| 
									
										
										
										
											2020-04-20 17:17:10 -07:00
										 |  |  | - [event: 'pageerror'](./api.md#event-pageerror) | 
					
						
							| 
									
										
										
										
											2020-04-20 16:56:46 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | <br/> | 
					
						
							| 
									
										
										
										
											2020-06-22 16:53:56 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | ## Page events
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #### `"requestfailed"`
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | page.on('requestfailed', request => { | 
					
						
							|  |  |  |   console.log(request.url() + ' ' + request.failure().errorText); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #### `"dialog"` - handle alert, confirm, prompt
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | page.on('dialog', dialog => { | 
					
						
							|  |  |  |   dialog.accept(); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #### `"popup"` - handle popup windows
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | const [popup] = await Promise.all([ | 
					
						
							|  |  |  |   page.waitForEvent('popup'), | 
					
						
							|  |  |  |   page.click('#open') | 
					
						
							|  |  |  | ]); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #### API reference
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - [class: Page](./api.md#class-page) | 
					
						
							|  |  |  | - [event: 'requestfailed'](./api.md#event-requestfailed) | 
					
						
							|  |  |  | - [event: 'dialog'](./api.md#event-dialog) | 
					
						
							|  |  |  | - [event: 'popup'](./api.md#event-popup) |