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 = [
|
2021-10-14 14:16:49 +00:00
|
|
|
`--window-size=${ 1920 },${ 1080 }`,
|
2021-10-19 11:00:24 +00:00
|
|
|
// '--disable-gpu'
|
|
|
|
// '--no-sandbox',
|
|
|
|
// '--single-process',
|
|
|
|
// '--no-zygote',
|
2021-10-14 14:16:49 +00:00
|
|
|
// '--disable-dev-shm-usage'
|
|
|
|
// '--full-memory-crash-report',
|
|
|
|
// '--unlimited-storage'
|
2020-03-24 10:12:59 +00:00
|
|
|
];
|
|
|
|
|
2021-10-14 14:16:49 +00:00
|
|
|
const env = process.env;
|
2020-04-03 13:14:53 +00:00
|
|
|
|
|
|
|
if (env.E2E_DEBUG) {
|
2020-03-24 10:12:59 +00:00
|
|
|
args.push('--auto-open-devtools-for-tabs');
|
2020-04-03 13:14:53 +00:00
|
|
|
env.E2E_SHOW = true;
|
|
|
|
}
|
2020-03-24 10:12:59 +00:00
|
|
|
|
2020-04-03 13:14:53 +00:00
|
|
|
const headless = !env.E2E_SHOW;
|
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,
|
2021-10-19 11:00:24 +00:00
|
|
|
slowMo: 5, // slow down by ms
|
2021-10-14 14:16:49 +00:00
|
|
|
// 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
|
|
|
|
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);
|
2021-10-11 09:20:15 +00:00
|
|
|
page.setDefaultTimeout(5000);
|
2021-10-18 14:09:07 +00:00
|
|
|
|
2020-03-23 22:57:11 +00:00
|
|
|
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;
|