salix/e2e/helpers/puppeteer.js

31 lines
886 B
JavaScript

import Puppeteer from 'puppeteer';
import {extendPage} from './extensions';
import {url as defaultURL} from './config';
export async function getBrowser() {
let headless = true;
const browser = await Puppeteer.launch({
args: [
'--no-sandbox',
`--window-size=${ 1920 },${ 1080 }`
],
defaultViewport: null,
headless: headless,
slowMo: 0, // slow down by ms
});
let page = (await browser.pages())[0];
page = extendPage(page);
page.setDefaultTimeout(5000);
// if (headless) {
// await page.setExtraHTTPHeaders({
// 'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8'
// });
// }
// await page.setCacheEnabled(false);
await page.goto(defaultURL, {waitUntil: 'networkidle0'});
return {page, close: browser.close.bind(browser)};
}
export default getBrowser;