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 #3630

Closed
Mehuge opened this issue Dec 6, 2018 · 7 comments
Closed

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

Mehuge opened this issue Dec 6, 2018 · 7 comments
Labels
chromium Issues with Puppeteer-Chromium

Comments

@Mehuge
Copy link

Mehuge commented Dec 6, 2018

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 1.11.0
  • Platform / OS version: MacOS Mojave 10.14
  • URLs (if applicable):
  • Node.js version: v10.11.0

What steps will reproduce the problem?

await puppeteer.launch({ headless: false, sloMo: 0, args: [
'--window-size=400,714',
'--unlimited-storage',
'--no-startup-window',
'--disable-dev-shm-usage',
'--disable-crash-reporter',
'--disable-breakpad'
]});

What is the expected result?

Chromium to launch, and puppeteer.launch() return.

What happens instead?

The dock icon for puppeteer appears, but puppeteer.launch() never returns.

I added a console.log to puppeteer/lib/Launcher.js to output the full command line being run, in case that helps.

/Users/adf/Projects/dalang/node_modules/puppeteer/.local-chromium/mac-609904/chrome-mac/Chromium.app/Contents/MacOS/Chromium --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=site-per-process --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --disable-translate --metrics-recording-only --no-first-run --safebrowsing-disable-auto-update --enable-automation --password-store=basic --use-mock-keychain about:blank --window-size=400,714 --unlimited-storage --no-startup-window --disable-dev-shm-usage --disable-crash-reporter --disable-breakpad --remote-debugging-port=0 --user-data-dir=/var/folders/7r/_3bt2vjs2lb7ql4tg98983x00000gn/T/puppeteer_dev_profile-l9JwIX

If I click on the dock icon that appeared for chromium, puppeteer.launch() then returns.

If I set executablePath to point at my normal Chrome executable (/Applications/Google Chrome.app/Contents/MacOS/Google Chrome), puppeteer.launch() works as expected.

@Mehuge Mehuge changed the title Downloaded chromium does not start puppeteer.launch() never returns Dec 6, 2018
@Mehuge
Copy link
Author

Mehuge commented Dec 6, 2018

Been trying a few things to get to try to get to the bottom of what is going, so I downgraded to puppeteer 1.3.0 (the version I was originally successfully using) and that works.

1.3.0 ok
1.4.0 ok
1.6.2 puppeteer.launch() hangs (until click dock icon)
1.4.0 ok

@aslushnikov aslushnikov added the chromium Issues with Puppeteer-Chromium label Dec 6, 2018
@Mehuge
Copy link
Author

Mehuge commented Dec 7, 2018

It's blocking on:- await initialPagePromise; in ensureInitialPage in Launcher.js

After calling Browser.create, before waiting for the initialPagePromise

puppeteer:protocol SEND ► {"id":1,"method":"Target.setDiscoverTargets","params":{"discover":true}} +0ms
puppeteer:protocol ◀ RECV {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"9606E8989A3213A624AB71E9AD5CD75A","type":"background_page","title":"CryptoTokenExtension","url":"chrome-extension://kmendfapggjehodndflmmgagdbamhnfd/_generated_background_page.html","attached":false,"browserContextId":"2D5F7FD876DC28A3F99652FB095AA448"}}} +11ms
puppeteer:protocol ◀ RECV {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"b9b8f636-2f8e-4714-bc0b-dfd3443171ff","type":"browser","title":"","url":"","attached":true}}} +1ms
puppeteer:protocol ◀ RECV {"id":1,"result":{}} +1ms

After calling await initialPagePromise:-

puppeteer:protocol ◀ RECV {"method":"Target.targetInfoChanged","params":{"targetInfo":{"targetId":"9606E8989A3213A624AB71E9AD5CD75A","type":"background_page","title":"CryptoTokenExtension","url":"chrome-extension://kmendfapggjehodndflmmgagdbamhnfd/_generated_background_page.html","attached":false,"browserContextId":"2D5F7FD876DC28A3F99652FB095AA448"}}} +123ms

Then after a short delay

puppeteer:protocol ◀ RECV {"method":"Target.targetDestroyed","params":{"targetId":"9606E8989A3213A624AB71E9AD5CD75A"}} +15s

@JoelEinbinder
Copy link
Collaborator

Puppeteer expects and waits for a page on startup. Passing --no-startup-window doesn't create the page. Why do you want to use this argument?

@Mehuge
Copy link
Author

Mehuge commented Dec 11, 2018

The way my code works is (in 1.3.0 and 1.4.0)

It calls puppeteer.launch() with --no-startup-window which means that browser.getPages() returns an empty list. So I then do if (pages.length === 0) pages.push(await browser.newPage()) which gives me a page I can then pages[0].goto(url); to navigate.

const browser = puppeteer.launch({ headless: false, args: [ '--no-startup-widnow' ] });
const pages = browser.pages();
if (pages.length === 0) pages.push(await browser.newPage());
pages[0].goto('http://www.google.com/');

All perfectly reasonable, I thought. But that code does not work since 1.6.2 because puppeteer.launch() blocks.

The error I am seeing if I don't add --no-startup-window is in the code below:

const connection = browser._connection;
const { targetInfos: [{ targetId }] } = await connection.send('Target.getTargets');
const { windowId } = await connection.send('Browser.getWindowForTarget', { targetId });
await connection.send('Browser.setWindowBounds', { bounds: { width, height }, windowId });

The issue is that the order of the two pages (targets) that is returned by Target.getTargets is different without --no-startup-window, the above code made the assumption (based on using --no-startup-window) of the order of the targets returned.

I can ofc fix my code to remove that assumption, but the real question is, is the first example considered code that should work? Because it certainly used to.

@Mehuge Mehuge changed the title puppeteer.launch() never returns puppeteer.launch() never returns when using --no-startup-window Dec 13, 2018
@aslushnikov
Copy link
Contributor

@Mehuge so what is the motivation to pass --no-startup-window flag? If you want to avoid creating second page and reuse the one that gets opened by default, you can get it like this:

const browser = await pptr.launch();
const [page] = await browser.pages();

@Mehuge
Copy link
Author

Mehuge commented Dec 14, 2018

That is essentially what my code is now doing.

https://github.com/redskyit/dalang/blob/master/dalang.js#L127

The motivation was indeed to avoid the second tab (in headless: false mode).

@aslushnikov
Copy link
Contributor

The motivation was indeed to avoid the second tab (in headless: false mode).

Looks like this is solved then :-)

OrKoN pushed a commit that referenced this issue May 6, 2021
The existing behavior is expected to be unchanged as the value defaults to true.
Adding such option would allow user to skip the initial wait.

Issue: #3630
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chromium Issues with Puppeteer-Chromium
Projects
None yet
Development

No branches or pull requests

4 participants
@Mehuge @aslushnikov @JoelEinbinder and others