Skip to content

[Checkly] adds "Browser Check #1" code #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions __checks__/browser-check-1.check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* This is a basic Playwright script to get you started!
* To learn more about Browser checks and Playwright visit: https://www.checklyhq.com/docs/browser-checks
*/

// Create a Chromium browser
const { chromium } = require('playwright')

// Checkly supports top level await, but we wrap your code in an async function so you can run it locally too.
async function run () {
const browser = await chromium.launch()
const page = await browser.newPage()

// We visit the page. This waits for the 'load' event by default.
const response = await page.goto('https://google.com')

// If the page doesn't return a successful response code, we fail the check.
if (response.status() > 399) {
throw new Error(`Failed with response code ${response.status()}`)
}

// We snap a screenshot.
await page.screenshot({ path: 'screenshot.jpg' })

// We close the page to clean up and gather performance metrics.
await page.close()
await browser.close()
}

run()