salix/e2e/helpers/puppeteer.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-11-25 08:13:20 +00:00
2019-12-12 07:37:35 +00:00
import Puppeteer from 'puppeteer';
import {extendPage} from './extensions';
import {url as defaultURL} from './config';
2019-11-25 08:13:20 +00:00
export async function getBrowser() {
2020-03-24 10:12:59 +00:00
const args = [
`--window-size=${ 1920 },${ 1080 }`,
// '--disable-gpu'
// '--no-sandbox',
// '--single-process',
// '--no-zygote',
// '--disable-dev-shm-usage'
// '--full-memory-crash-report',
// '--unlimited-storage'
2020-03-24 10:12:59 +00:00
];
const env = process.env;
if (env.E2E_DEBUG) {
2020-03-24 10:12:59 +00:00
args.push('--auto-open-devtools-for-tabs');
env.E2E_SHOW = true;
}
2020-03-24 10:12:59 +00:00
2023-05-23 11:31:09 +00:00
const headless = env.E2E_SHOW ? false : 'new';
const browser = await Puppeteer.launch({
2020-03-24 10:12:59 +00:00
args,
defaultViewport: null,
2020-02-04 15:21:10 +00:00
headless: headless,
2023-06-28 07:59:55 +00:00
slowMo: 20, // slow down by ms
// ignoreDefaultArgs: ['--disable-extensions'],
// executablePath: '/usr/bin/google-chrome-stable',
// executablePath: '/usr/bin/firefox-developer-edition',
2019-12-12 07:37:35 +00:00
});
2020-03-24 10:12:59 +00:00
let page = (await browser.pages())[0];
2020-02-12 13:36:05 +00:00
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)};
2019-12-12 07:37:35 +00:00
}
2019-11-25 08:13:20 +00:00
export default getBrowser;