39 lines
928 B
JavaScript
39 lines
928 B
JavaScript
|
|
import Puppeteer from 'puppeteer';
|
|
import {extendPage} from './extensions';
|
|
import {url as defaultURL} from './config';
|
|
|
|
let browser;
|
|
|
|
export function getBrowser() {
|
|
return browser || {close: () => {}};
|
|
}
|
|
|
|
async function openPage(url = defaultURL) {
|
|
if (!browser) {
|
|
browser = await Puppeteer.launch({
|
|
args: [
|
|
'--start-maximized'
|
|
// '--start-fullscreen'
|
|
],
|
|
defaultViewport: null,
|
|
headless: false,
|
|
slowMo: 0, // slow down by ms
|
|
});
|
|
}
|
|
const page = await browser.newPage();
|
|
await page.setDefaultTimeout(5000);
|
|
await page.goto(url, {waitUntil: 'networkidle0'});
|
|
|
|
page.on('console', msg => {
|
|
let type = msg.type();
|
|
if (type === 'error')
|
|
console[type](msg.text());
|
|
});
|
|
|
|
const extendedPage = extendPage(page);
|
|
return extendedPage;
|
|
}
|
|
|
|
export default openPage;
|