salix/e2e/helpers/puppeteer.js

57 lines
1.5 KiB
JavaScript

import Puppeteer from 'puppeteer';
import {extendPage} from './extensions';
import {url as defaultURL} from './config';
export async function getBrowser() {
const args = [
`--window-size=${ 1920 },${ 1080 }`,
// '--disable-gpu'
// '--no-sandbox',
// '--single-process',
// '--no-zygote',
// '--disable-dev-shm-usage'
// '--full-memory-crash-report',
// '--unlimited-storage'
];
const 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: 5, // slow down by ms
// ignoreDefaultArgs: ['--disable-extensions'],
// executablePath: '/usr/bin/google-chrome-stable',
// executablePath: '/usr/bin/firefox-developer-edition',
});
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(5000);
await page.goto(defaultURL, {waitUntil: 'load'});
return {page, close: browser.close.bind(browser)};
}
export default getBrowser;