37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
|
|
import Puppeteer from 'puppeteer';
|
|
import {extendPage} from './extensions';
|
|
import {url as defaultURL} from './config';
|
|
|
|
export async function getBrowser() {
|
|
let headless = !process.env.E2E_SHOW;
|
|
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];
|
|
await page.evaluateOnNewDocument(() => {
|
|
Object.defineProperty(navigator, 'language', {
|
|
get: function() {
|
|
return 'en';
|
|
}
|
|
});
|
|
Object.defineProperty(navigator, 'languages', {
|
|
get: function() {
|
|
return ['en'];
|
|
}
|
|
});
|
|
});
|
|
page = extendPage(page);
|
|
page.setDefaultTimeout(10000);
|
|
await page.goto(defaultURL, {waitUntil: 'networkidle0'});
|
|
return {page, close: browser.close.bind(browser)};
|
|
}
|
|
|
|
export default getBrowser;
|