Skip to content

Commit

Permalink
Add useragent javascript example
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Nov 12, 2024
1 parent 131a3ec commit 87719e6
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions examples/useragent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { browser } from 'k6/x/browser/async';
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';

export const options = {
scenarios: {
ui: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
thresholds: {
checks: ["rate==1.0"]
}
}

export default async function() {
let context = await browser.newContext({
userAgent: 'k6 test user agent',
})
let page = await context.newPage();
await check(page, {
'user agent is set': async p => {
const userAgent = await p.evaluate(() => navigator.userAgent);
return userAgent.includes('k6 test user agent');
}
});
await page.close();
await context.close();

context = await browser.newContext();
check(context.browser(), {
'user agent does not contain headless': b => {
return b.userAgent().includes('Headless') === false;
}
});

page = await context.newPage();
await check(page, {
'chromium user agent does not contain headless': async p => {
const userAgent = await p.evaluate(() => navigator.userAgent);
return userAgent.includes('Headless') === false;
}
});
await page.close();
}

0 comments on commit 87719e6

Please sign in to comment.