easy-puppeteer-html

1.0.2 • Public • Published

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

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);
});

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

Package Sidebar

Install

npm i easy-puppeteer-html

Weekly Downloads

121

Version

1.0.2

License

MIT

Unpacked Size

10.9 kB

Total Files

10

Last publish

Collaborators

  • hubcarl