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

support chrome-headless-shell (old headless mode) #918

Merged
merged 1 commit into from
Feb 17, 2025

Conversation

vintagesucks
Copy link
Contributor

@vintagesucks vintagesucks commented Jan 30, 2025

headless: request.options.newHeadless ? 'new' : true,

In current Puppeteer versions (v22+ according to the docs), {headless: true} actually launches the new headless mode, while {headless: 'shell'} launches the old mode:

This makes it currently impossible to use the old headless mode with Browsershot, which is our preferred mode for creating PDFs, and the only mode that, in our experience, actually works with Basic Auth.

See https://developer.chrome.com/blog/chrome-headless-shell for more details.


Note: We were previously able to work around this issue by enabling the old headless mode the following way instead:

$browsershot->addChromiumArguments([
    'headless' => 'old', // see https://developer.chrome.com/docs/chromium/headless#use_old_headless_mode
]);

As of Puppeteer v24.1.0, this workaround unfortunately does not work anymore, as old is not a valid option anymore:

================ Error Output: ================
sh: npm: command not found Error: Failed to launch the browser process!

Old Headless mode has been removed from the Chrome binary. Please use the 
new Headless mode (https://developer.chrome.com/docs/chromium/new-headless)
or the chrome-headless-shell which is a standalone implementation of the old
Headless mode (https://developer.chrome.com/blog/chrome-headless-shell).

TROUBLESHOOTING: https://pptr.dev/troubleshooting

@clementmas
Copy link
Contributor

I also made a PR to fix this issue but it introduced a breaking change: #907

I believe your PR would also introduce a breaking change because it would change the default mode to old headless.

So until a new major version is released, the workaround is probably to add a new oldHeadless method alongside the now useless newHeadless method.

@vintagesucks
Copy link
Contributor Author

vintagesucks commented Feb 17, 2025

Changing the default to the old headless mode isn't a breaking change in my eyes, as this was always the default in Browsershot until Puppeteer updates changed that. Using $browsershot->newHeadless() will still launch the new headless mode, and users not using this method might have expected to launch the old mode anyway. Browsershot 5.0.0 requires Puppeteer 23 or higher, so this is essentially a bug fix to keep things as they were.

We use $browsershot->authenticate(), which stopped working with Puppeteer 22 unless the old headless mode was used, and with Puppeteer 24.1.0 (or rather with the chrome version that is paired with it) there is currently no way to use the old headless mode with Browsershot.

@freekmurze freekmurze merged commit 0102971 into spatie:main Feb 17, 2025
1 of 7 checks passed
@freekmurze
Copy link
Member

Thanks!

@vintagesucks vintagesucks deleted the headless branch February 17, 2025 12:28
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

Successfully merging this pull request may close these issues.

3 participants