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
|
|
|
|
2020-01-14 08:20:14 +00:00
|
|
|
export async function getBrowser() {
|
2020-03-24 10:12:59 +00:00
|
|
|
const args = [
|
|
|
|
`--no-sandbox`,
|
|
|
|
`--window-size=${ 1920 },${ 1080 }`
|
|
|
|
];
|
|
|
|
|
|
|
|
if (process.env.DEBUG)
|
|
|
|
args.push('--auto-open-devtools-for-tabs');
|
|
|
|
|
2020-03-24 16:27:21 +00:00
|
|
|
const headless = !(process.env.E2E_SHOW || process.env.DEBUG);
|
2020-01-14 08:20:14 +00:00
|
|
|
const browser = await Puppeteer.launch({
|
2020-03-24 10:12:59 +00:00
|
|
|
args,
|
2020-01-14 08:20:14 +00:00
|
|
|
defaultViewport: null,
|
2020-02-04 15:21:10 +00:00
|
|
|
headless: headless,
|
2020-01-14 08:20:14 +00:00
|
|
|
slowMo: 0, // slow down by ms
|
2019-12-12 07:37:35 +00:00
|
|
|
});
|
2020-03-24 10:12:59 +00:00
|
|
|
|
2020-01-14 08:20:14 +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'];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2020-01-14 08:20:14 +00:00
|
|
|
page = extendPage(page);
|
2020-03-23 22:57:11 +00:00
|
|
|
page.setDefaultTimeout(4000);
|
|
|
|
await page.goto(defaultURL, {waitUntil: 'load'});
|
2020-01-14 08:20:14 +00:00
|
|
|
return {page, close: browser.close.bind(browser)};
|
2019-12-12 07:37:35 +00:00
|
|
|
}
|
2019-11-25 08:13:20 +00:00
|
|
|
|
2020-01-14 08:20:14 +00:00
|
|
|
export default getBrowser;
|