@jswebscraper/puppeteerwrapper
v0.0.2
Published
Wraps Puppeteer methods to expose an easy interface for grabbing and dumping page HTML
Downloads
6
Readme
PuppeteerWrapper
Description
A Class that wraps a Headless Chrome browser (using Puppeteer) and its pages and exposes simple methods to help retrieve HTML from lists of links.
PuppeteerWrapper Class
Attributes
| Attribute | Description | | :---------- | ----------- | | pages | An Array[Object] that holds pages and page metadata | | browser | A Puppeteer browser |
Methods
| Method | Description |
| :---------- | ----------- |
| init ()returns: Promise.resolve(undefined
) | Async method that must be called after initializing a new PuppeteerWrapper
.It sets this.pages
to an empty Array and sets this.browser
after awaitingthe launch of a new Puppeteer browser. |
| getBrowser ()returns: Object | Getter that returns this.browser
Object, which contains a Puppeteer browserand metadata |
| getPages ()returns: Array[Object] | Getter that returns this.pages
Array, which contains a list of page Objects withPuppeteer pages and metadata |
| getPageCount ()returns: Number | Returns this.pages.length
|
| getPageById (id)returns: Object | Returns the page Object with a given Number id
|
| getPageByName (name)returns: Object | Returns the page Object with a given String name
|
| closePages ()returns: Promise.resolve(undefined
) | Loops through this.pages
, closing every Puppeteer page, and then emptiesthis.pages
|
| teardown ()returns: Promise.resolve(undefined
) | Closes all pages, and then closes this.browser
|
| openPages (num)returns: Promise.resolve(undefined
) | Opens Number num
Puppeteer pages and adds them to this.pages
|
| getDOM (urls)returns: Promise.resolve(String or Array[String]) | Can be called with a single URL Object (containing String URL,and String GPU name), or an Array of URL Objects. Will returnthe HTML for the single URL/list of URLs. |
Testing
Testing is executed using Jest. All test files are maintained in the PuppeteerWrapper/test/
directory. To run unit tests, run npm run test
.
Code Style
All code is styled using JavaScript Standard Style.