Skip to content

Instantly share code, notes, and snippets.

@checklyalex
Created January 19, 2024 14:21
Show Gist options
  • Save checklyalex/7eb16d73bcde329e4d17f75903cb2c00 to your computer and use it in GitHub Desktop.
Save checklyalex/7eb16d73bcde329e4d17f75903cb2c00 to your computer and use it in GitHub Desktop.
A Checkly browser check example utilising a separate context and extra HTTP headers - https://playwright.dev/docs/api/class-page#page-set-extra-http-headers
import { expect, test } from '@playwright/test'
const headers = {
'X-My-Header': 'value'
};
test('visit page and take screenshot with an extra http header for every request', async ({ browser }) => {
const context = await browser.newContext();
await context.setExtraHTTPHeaders(headers);
const page = await context.newPage();
const response = await page.goto(process.env.ENVIRONMENT_URL || 'https://checklyhq.com')
expect(response.status(), 'should respond with correct status code').toBeLessThan(400)
await context.close();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment