Capture HTML Content By Puppeteer
npm install easy-puppeteer-html --save
const puppeteer = require('easy-puppeteer-html');
const puppeteer.capture({
url: 'http://49.233.172.37:7001/csr',
selector: '#app',
waitSelector: '#app',
beforeEvaluate: async (browser, page) => {
await page.setUserAgent('Mozilla/5.0 (Linux; U; Android 9; en-US) Chrome/57.0.2987.108 UCBrowser/12.12.5.1189 Mobile');
},
afterEvaluate: async (browser, page, html) => {
return html;
}
}).then(html => {
console.log(html);
});
PuppeteerHtmlPrerenderPlugin options:
- url - prefetch render url
- filepath - need prerender dist file path, prerender content will inject into the file
- selector { optional } - fetch selector element html. if not exist, will return all html.
- selectorOuterHTML { optional, default: true } - return selector self node content.
- waitSelector { optional } - fetch selector element html until waiting selector element exist, the config can get the client render mode html content.
- base64 { optional, default: false } - img with class="base64" is automatically converted to base64
- debug { optional, default: false } - print puppeteer execute cost and key info
- beforeEvaluate { optional } - before evaluate fetch hook
- afterEvaluate { optional } - after evaluate fetch hook