Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async start() {
this._browser = await pptr.launch({
headless: this._headless,
executablePath: this._executablePath,
pipe: this._pipe,
}).catch((err) => console.log(err));
this._page = await this._browser.pages()
.then((pageArr) => {
return pageArr[0];
});
this._page.goto(this._url, { waitUntil: 'networkidle0' });
return await this._page;
}
// Recursive React component scraping algorithm
static async openBrowser(t) {
t.context.browser = await puppeteer.launch({
executablePath: process.env.CHROME_PATH,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
],
});
}
async function downloadOrLocatePreferredBrowserRevision() {
const browserFetcher = puppeteer.createBrowserFetcher();
const preferredRevision = puppeteer._launcher._preferredRevision;
const localRevisions = await browserFetcher.localRevisions();
let revisionInfo;
if (localRevisions.includes(preferredRevision)) {
revisionInfo = await browserFetcher.revisionInfo(preferredRevision);
} else {
console.log(`Downloading Chromium ${preferredRevision}`);
revisionInfo = await browserFetcher.download(preferredRevision);
}
return puppeteer.launch({
executablePath: revisionInfo.executablePath
});
}
public async start() {
this._browser = await pptr.launch(
{
headless: this._headless,
executablePath: this._executablePath,
pipe: this._pipe,
}
).catch((err: any) => console.log(err));
this._page = await this._browser.pages()
.then((pageArr: any) => {
return pageArr[0];
});
this._page.goto(this._url, { waitUntil: 'networkidle0' });
return await this._page;
}
`;
const args = [
`--app=data:text/html,${targetPage}`,
`--enable-features=NetworkService,NetworkServiceInProcess`,
];
if (options.args)
args.push(...options.args);
if (typeof options.width === 'number' && typeof options.height === 'number')
args.push(`--window-size=${options.width},${options.height}`);
if (typeof options.left === 'number' && typeof options.top === 'number')
args.push(`--window-position=${options.left},${options.top}`);
try {
const browser = await puppeteer.launch({
executablePath,
pipe: true,
defaultViewport: null,
headless: testMode,
userDataDir: options.userDataDir || path.join(options.localDataDir, `profile-${type}`),
args });
const app = new App(browser, options);
await app.init_();
return app;
} catch (e) {
if (e.toString().includes('Target closed'))
throw new Error('Could not start the browser or the browser was already running with the given profile.');
else
throw e;
}
}
if (options.detached) {
debug(`Starting browser in detached mode with options:
${JSON.stringify(options, null, 2)}
`);
try {
browser = await startDetached(options);
} catch (e) {
debug(e);
throw e;
}
} else {
debug(`Starting browser in regular mode with options:
${JSON.stringify(options, null, 2)}
`);
browser = await puppeteer.launch(options);
}
debug(`Creating new page`);
/**
* When the browser starts there's usually a blank page,
* instead of creating a new one to navigate, it is reused.
* If none is available, then a new one is created.
*/
const pages = await browser.pages();
const page = pages.length > 0 ?
await pages[0] :
await browser.newPage();
page.setDefaultTimeout(options.timeout || TIMEOUT);
async function handler ({ cwd, output }) {
const executablePath = process.env.PUPPETEER_EXECUTABLE_PATH || (await (chromeFinder)[getPlatform()]())[0]
if (!executablePath) {
throw new Error('Chrome / Chromium is not installed or environment variable PUPPETEER_EXECUTABLE_PATH is not set')
}
let browser = await puppeteer.launch({ executablePath })
let page = await browser.newPage()
await page.goto(`file://${cwd}/index.html`)
const [width, height] = await page.evaluate(async () => {
const container = document.querySelector('.shower')
const styles = window.getComputedStyle(container)
return [
styles.getPropertyValue('--slide-width'),
styles.getPropertyValue('--slide-height')
]
})
await page.pdf({