optimize and debug
This commit is contained in:
parent
61a910f3bf
commit
999ccfe57c
14
index.js
14
index.js
@ -8,7 +8,7 @@ let [
|
|||||||
url,
|
url,
|
||||||
title = '',
|
title = '',
|
||||||
subtitle = '',
|
subtitle = '',
|
||||||
date = moment().format('YYYY-MM-DD')
|
date = moment().format('YYY-MM-DD')
|
||||||
] = process.argv.slice(2);
|
] = process.argv.slice(2);
|
||||||
|
|
||||||
const path = './pdf';
|
const path = './pdf';
|
||||||
@ -31,12 +31,8 @@ try{
|
|||||||
|
|
||||||
// open page
|
// open page
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
page.setDefaultNavigationTimeout(0);
|
await page.goto(url, { waitUntil: 'networkidle0' });
|
||||||
await page.goto(url);
|
console.log('page loaded');
|
||||||
await Promise.any([
|
|
||||||
page.mainFrame().waitForNavigation({waitUntil: 'networkidle0'}),
|
|
||||||
new Promise(resolve => setTimeout(resolve,2000))
|
|
||||||
]);
|
|
||||||
|
|
||||||
// search for header and subheader in document
|
// search for header and subheader in document
|
||||||
if (!title) title = await (await page.waitForSelector('h1')).evaluate(el => el.textContent);
|
if (!title) title = await (await page.waitForSelector('h1')).evaluate(el => el.textContent);
|
||||||
@ -48,7 +44,7 @@ try{
|
|||||||
// deactivate @print css and add custom css (for pretty code)
|
// deactivate @print css and add custom css (for pretty code)
|
||||||
await page.emulateMediaType('screen');
|
await page.emulateMediaType('screen');
|
||||||
await page.addStyleTag({content: `
|
await page.addStyleTag({content: `
|
||||||
body{
|
body {
|
||||||
text-shadow: none !important;
|
text-shadow: none !important;
|
||||||
}
|
}
|
||||||
.hidden-print {
|
.hidden-print {
|
||||||
@ -79,7 +75,7 @@ try{
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 2mm;
|
padding: 2mm;
|
||||||
border-bottom: 1px #222 solid;
|
border-bottom: 1px #222 solid;
|
||||||
">${[title, subtitle].map(el=>el.trim()).filter(el=>!!el).join(' - ')}</div>
|
">${[title, subtitle].map(el=>el.trim()).filter(el=>!!el).join(' | ')}</div>
|
||||||
`,
|
`,
|
||||||
footerTemplate: `
|
footerTemplate: `
|
||||||
<div style="
|
<div style="
|
||||||
|
Loading…
Reference in New Issue
Block a user