salix/e2e/helpers/puppeteer.js

47 lines
1.1 KiB
JavaScript

import Puppeteer from 'puppeteer';
import {extendPage} from './extensions';
import {url as defaultURL} from './config';
export async function getBrowser() {
const args = [
`--no-sandbox`,
`--window-size=${ 1920 },${ 1080 }`
];
let env = process.env;
if (env.E2E_DEBUG) {
args.push('--auto-open-devtools-for-tabs');
env.E2E_SHOW = true;
}
const headless = !env.E2E_SHOW;
const browser = await Puppeteer.launch({
args,
defaultViewport: null,
headless: headless,
slowMo: 0, // slow down by ms
});
let page = (await browser.pages())[0];
await page.evaluateOnNewDocument(() => {
Object.defineProperty(navigator, 'language', {
get: function() {
return 'en';
}
});
Object.defineProperty(navigator, 'languages', {
get: function() {
return ['en'];
}
});
});
page = extendPage(page);
page.setDefaultTimeout(4000);
await page.goto(defaultURL, {waitUntil: 'load'});
return {page, close: browser.close.bind(browser)};
}
export default getBrowser;