43 lines
1.1 KiB
JavaScript
43 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 }`
|
|
];
|
|
|
|
if (process.env.DEBUG)
|
|
args.push('--auto-open-devtools-for-tabs');
|
|
|
|
const headless = !(process.env.E2E_SHOW || process.env.DEBUG);
|
|
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;
|