Skip to content

Commit

Permalink
Merge 07fb497 into d16798c
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Sep 10, 2018
2 parents d16798c + 07fb497 commit 924735f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -84,6 +84,22 @@ https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunc

By default the library will be pass a well known list of flags, so probably you don't need any additional setup.

##### timeout

type:`number`</br>
default: `30000`

This setting will change the default maximum navigation time.

##### incognito

type:`boolean`</br>
default: `true`

Every time a new page is created, it will be an incognito page.

An incognito page will not share cookies/cache with other browser pages.

### .pool(options)

Tha main **browserless** constructor expose a singleton browser. This is enough for most scenarios, but in case you need you can intialize a **pool of instances**.
Expand Down
18 changes: 14 additions & 4 deletions src/browserless.js
Expand Up @@ -36,7 +36,11 @@ const createTempFile = opts => {
// The puppeteer launch causes many events to be emitted.
process.setMaxListeners(0)

module.exports = launchOpts => {
module.exports = ({
incognito = true,
timeout = 30000,
...launchOpts
} = {}) => {
let browser = puppeteer.launch({
ignoreHTTPSErrors: true,
args: [
Expand All @@ -52,14 +56,20 @@ module.exports = launchOpts => {
'--no-pings',
'--no-sandbox',
'--no-zygote',
'--prerender-from-omnibox=disabled',
'--single-process'
'--prerender-from-omnibox=disabled'
],
...launchOpts
})

const newPage = () =>
Promise.resolve(browser).then(browser => browser.newPage())
Promise.resolve(browser).then(async browser => {
const context = incognito
? await browser.createIncognitoBrowserContext()
: browser
const page = await context.newPage()
page.setDefaultNavigationTimeout(timeout)
return page
})

const goto = async (
page,
Expand Down

0 comments on commit 924735f

Please sign in to comment.