# Browser check structure - Checkly Docs

> Learn how to structure your Browser checks with Monitoring as Code.

Source: https://www.checklyhq.com/docs/detect/synthetic-monitoring/browser-checks/mac-structure/

---

Back to top
- Browser check construct
- Test Script Structure
- Environment variables Built-in runtime variables

Browser Checks

# Browser check structure

Learn how to structure your Browser checks with Monitoring as Code.

Monitoring as Code works by connecting Playwrighttest files with Checkly constructs to handle the end-to-endconfiguration of your Browser check.

## ​ Browser check construct

The Browser check construct is used to configure your monitoring settings, such as frequency, locations, and tags. Learn more about the [Browser check construct](https://www.checklyhq.com/docs/constructs/browser-check)
browser-check.ts

```
import { BrowserCheck, Frequency } from 'checkly/constructs'
import * as path from 'path'

new BrowserCheck('browser-check-1', {
name: 'Browser check #1',
frequency: Frequency.EVERY_10M,
locations: ['us-east-1', 'eu-west-1'],
code: {
entrypoint: path.join(__dirname, 'login.spec.js')
}
})
```

## ​ Test Script Structure

Checkly uses Playwright to power Browser checks. [Playwright](https://playwright.dev/docs/intro) is a robust, open-source framework for browser automation and end-to-end web application testing. It enables you to write atomic, reliable tests and easily control interactions within a web page. Browser checks execute automated test scripts in real browsers.
login.spec.ts

```
// Use environment-specific URLs and credentials
const baseURL = process.env.BASE_URL || 'https://app.example.com'
const testUser = process.env.TEST_USER_EMAIL
const testPassword = process.env.TEST_USER_PASSWORD

test('Environment-aware test', async ({ page }) => {
await page.goto(`${baseURL}/login`)
await page.fill('[name="email"]', testUser)
await page.fill('[name="password"]', testPassword)
// ... rest of test
})
```

## ​ Environment variables

[Check, group and global variables](https://www.checklyhq.com/docs/platform/variables) are accessible in your code using the standard Node.js `process.env.MY_VAR` notation. For example, the code snippet below show how you can log into GitHub.
variables.spec.ts

```
import { test } from '@playwright/test'

test('GitHub login', async ({ page }) => {
await page.goto('https://github.com/login')
await page.getByLabel('Username or email address').type(process.env.GITHUB_USER)
await page.getByLabel('Password').type(process.env.GITHUB_PWD)
await page.getByRole('button', { name: 'Sign in' }).click()
})
```

```
const { test } = require('@playwright/test')

test('GitHub login', async ({ page }) => {
await page.goto('https://github.com/login')
await page.getByLabel('Username or email address').type(process.env.GITHUB_USER)
await page.getByLabel('Password').type(process.env.GITHUB_PWD)
await page.getByRole('button', { name: 'Sign in' }).click()
})
```

### ​ Built-in runtime variables

Our [check runtimes](https://www.checklyhq.com/docs/platform/runtimes/overview/) also expose a set of environment variables (e.g. `process.env.CHECK_NAME`)
to figure out what check, check type etc. you are running.
Variable Description Availability

`ACCOUNT_ID` The ID of the account the check belongs to.

`CHECK_ID` The UUID of the check being executed. Only available after saving the check.

`CHECK_NAME` The name of the check being executed.

`CHECK_RESULT_ID` The UUID where the result will be saved. Only available on scheduled runs.

`CHECK_RUN_ID` The UUID of the check run execution. Only available on scheduled runs.

`CHECK_TYPE` The type of the check, e.g. `BROWSER`.

`CHECKLY_TRACE_ID` The OpenTelemetry trace ID of the check run. Use it to correlate the run with the trace in your own observability backend. Only in Browser checks, Multistep checks, Playwright Check Suites, and API setup & teardown scripts, and only when [Traces](https://www.checklyhq.com/docs/resolve/traces/overview) is active for the check, unset otherwise.

`CHECKLY_TRACEPARENT` The W3C `traceparent` header value of the check run’s trace. Use it to propagate the trace context to your own tooling. Only in Browser checks, Multistep checks, Playwright Check Suites, and only when [Traces](https://www.checklyhq.com/docs/resolve/traces/overview) is active for the check, unset otherwise.

`CHECKLY_TRACESTATE` The W3C `tracestate` header value of the check run’s trace. Use it with `CHECKLY_TRACEPARENT` to propagate the full trace context. Only in Browser checks, Multistep checks, Playwright Check Suites, and only when [Traces](https://www.checklyhq.com/docs/resolve/traces/overview) is active for the check, unset otherwise.

`PUBLIC_IP_V4` The IPv4 of the check run execution.

`PUBLIC_IP_V6` The IPv6 of the check run execution.

`REGION` The current region, e.g. `us-west-1`.

`RUNTIME_VERSION` The version of the runtime, e.g, `2023.09`. Only in Browser, Multistep, and API setup/teardown scripts.

Was this page helpful?

[Suggest edits](https://github.com/checkly/docs/edit/main/detect/synthetic-monitoring/browser-checks/mac-structure.mdx)[Raise issue](https://github.com/checkly/docs/issues/new?title=Issue%20on%20docs&body=Path:%20/detect/synthetic-monitoring/browser-checks/mac-structure)

[Creating a Browser check Previous](https://www.checklyhq.com/docs/detect/synthetic-monitoring/browser-checks/quickstart)[Performance & Web Vitals Next](https://www.checklyhq.com/docs/detect/synthetic-monitoring/browser-checks/performance-metrics)

[x](https://x.com/checklyhq)[github](https://github.com/checkly)[linkedin](https://linkedin.com/company/checkly)

[Powered by This documentation is built and hosted on Mintlify, a developer documentation platform](https://www.mintlify.com/?utm_campaign=poweredBy&utm_medium=referral&utm_source=checkly-422f444a)
