Skip to content

Commit 5c4c8db

Browse files
authored
Merge pull request #1 from mhmh261/checkly/browser-check-1_7tb3v
[Checkly] adds "Browser Check #1" code
2 parents 9dac9f7 + ba9b47e commit 5c4c8db

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

__checks__/browser-check-1.check.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* This is a basic Playwright script to get you started!
3+
* To learn more about Browser checks and Playwright visit: https://www.checklyhq.com/docs/browser-checks
4+
*/
5+
6+
// Create a Chromium browser
7+
const { chromium } = require('playwright')
8+
9+
// Checkly supports top level await, but we wrap your code in an async function so you can run it locally too.
10+
async function run () {
11+
const browser = await chromium.launch()
12+
const page = await browser.newPage()
13+
14+
// We visit the page. This waits for the 'load' event by default.
15+
const response = await page.goto('https://google.com')
16+
17+
// If the page doesn't return a successful response code, we fail the check.
18+
if (response.status() > 399) {
19+
throw new Error(`Failed with response code ${response.status()}`)
20+
}
21+
22+
// We snap a screenshot.
23+
await page.screenshot({ path: 'screenshot.jpg' })
24+
25+
// We close the page to clean up and gather performance metrics.
26+
await page.close()
27+
await browser.close()
28+
}
29+
30+
run()

0 commit comments

Comments
 (0)