1.1.1 • Published 5 years ago

get-puppeteer-browser v1.1.1

Weekly downloads
8
License
MIT
Repository
github
Last release
5 years ago

get-puppeteer-browser

Get a singleton puppeteer browser instance.

npm license

Creating a puppeteer browser instance is very slow. It is usually better to reuse than to create each time.

Install

npm i get-puppeteer-browser

Example

const createBrowserGetter = require('get-puppeteer-browser')
const puppeteer = require('puppeteer')

const getBrowser = createBrowserGetter(puppeteer, {headless: true, devtools: true});

(async () => {
    const b1 = await getBrowser()
    const b2 = await getBrowser()

    console.log(b1 === b2) // => true

    await b1.close() // Not yet closed
    await b2.close() // Close now.
})()

API

createBrowserGetter(puppeteer, launchOptions)

Create a getBrowser function.

Debounce option

Debounce without closing immediately.

const getBrowser = createBrowserGetter(puppeteer, {debounce: 1000});

(async () => {
    const b1 = await getBrowser()
    b1.close()

    delay(900).then(async () => {
        const b2 = await getBrowser()
        console.log(b1 === b2) // => true
        b2.close()

        delay(1000).then(async () => {
            const b3 = await getBrowser()
            console.log(b2 === b3) // => false
        })
    })
})()

License

MIT

1.1.1

5 years ago

1.1.0

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago