项目作者: easy-team

项目描述 :
puppeteer prerender html
高级语言: JavaScript
项目地址: git://github.com/easy-team/easy-puppeteer-html.git
创建时间: 2020-01-06T07:43:15Z
项目社区:https://github.com/easy-team/easy-puppeteer-html

开源协议:

下载


easy-puppeteer-html

NPM version
build status
Test coverage
David deps
Known Vulnerabilities
npm download

Capture HTML Content By Puppeteer

Install

npm install easy-puppeteer-html —save

Usage

  1. const puppeteer = require('easy-puppeteer-html');
  2. const puppeteer.capture({
  3. url: 'http://49.233.172.37:7001/csr',
  4. selector: '#app',
  5. waitSelector: '#app',
  6. beforeEvaluate: async (browser, page) => {
  7. await page.setUserAgent('Mozilla/5.0 (Linux; U; Android 9; en-US) Chrome/57.0.2987.108 UCBrowser/12.12.5.1189 Mobile');
  8. },
  9. afterEvaluate: async (browser, page, html) => {
  10. return html;
  11. }
  12. }).then(html => {
  13. console.log(html);
  14. });

Configuration

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

License

MIT