Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

puppeteer.launch() never returns when using --no-startup-window #4298

Closed
EmrysMyrddin opened this issue Apr 17, 2019 · 3 comments
Closed

puppeteer.launch() never returns when using --no-startup-window #4298

EmrysMyrddin opened this issue Apr 17, 2019 · 3 comments

Comments

@EmrysMyrddin
Copy link

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 1.14.0
  • Platform / OS version: macOS
  • URLs (if applicable):
  • Node.js version: 11.9.0

What steps will reproduce the problem?

Please include code that reproduces the issue.

const browser = await puppeteer.launch({ args: ['--no-startup-window'] })

What is the expected result?

The launch function should return a promise which resolve to a browser.

What happens instead?

The launch call is hanging and never resolve.

An other closed issue already reported this problem (#3630), but I can't use the given workaround in my case. And i think that even if there is a workaround, this is still bug since the behavior is unexpected.

@EmrysMyrddin
Copy link
Author

EmrysMyrddin commented Apr 17, 2019

I add here my use case to explain why I can't use the workaround of #3630

I'm using puppeteer to render pdf document from web page. It is a web service and I wanted to allow each instance of my service to have multiple "renderer" (multiple pages in facts).

To implement this, I'm using a generic pool implementation which allow me to create a pool of page ready to be used.

const puppeteer = require('puppeteer')
const genericPool = require('generic-pool')
const { goToLogin } = require('./utils')

let pagePool

// Browser singleton
const getBrowser = (() => {
  let memoizedBrowserPromise
  return () => {
    if (!memoizedBrowserPromise) {
      memoizedBrowserPromise = puppeteer.launch({ args: ['--no-startup-window'] })
    }
    return memoizedBrowserPromise
  }
})()

// The generic pool uses a factory with 3 functions:
//   - create: create a new ressource.
//   - destroy: destroy the given ressource. Commonly used to destroy a ressource on error
//   - validate: validate is a ressource is still valid. Used by the pool to periodically check if it needs to clean up some ressources.
const pageFactory = {
  async create() {
    const browser = await getBrowser()
    // Here, I can't use `const [page] = await browser.pages()` since this function can be called at any time.
    const page = await browser.newPage()

    const onError = (error) => pagePool.destroy(page)

    page.on('error', onError)
    page.on('pageerror', onError)

    await goToLogin(page)

    return page
  },
  async destroy(page) {
    if (page.isClosed()) await page.close()
  },
  async validate(page) {
    return page.isClosed()
  },
}

pagePool = genericPool.createPool(pageFactory, { min: 1, max: 5 })

module.exports = pagePool

@JoelEinbinder
Copy link
Collaborator

--no-startup-window is in't even supported by headless chrome. Having an extra blank page uses no CPU and very little memory. I wouldn't worry about it.

@EmrysMyrddin
Copy link
Author

I didn't even notice that it wasn't working on headless... It's difficult to see what's happening in headless ^^

Thanks for the advice, if it has no real impact, I will ignore this then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants