Hey everyone,
I’m working on a Puppeteer project and I’ve hit a bit of a snag. I started with a headless browser instance, but now I need to see what’s happening visually. Is there a way to switch a headless browser to non-headless mode without losing my current session?
I tried changing the headless
option to false
while the browser was running, but it didn’t seem to do anything. The browser stayed invisible.
Has anyone figured out a trick for this? Maybe there’s a method I’m missing or a different approach altogether? I’d really appreciate any insights or workarounds you might have!
Thanks for your help!
As someone who’s worked extensively with Puppeteer, I can confirm that switching from headless to non-headless mid-session isn’t possible. It’s a limitation of how Puppeteer initializes the browser instance.
However, here’s a trick I’ve used: Instead of starting headless, launch with headless: false but set the browser window size to 0x0. This keeps it technically visible but practically invisible. When you need to see it, use page.setViewport() to resize it.
Another approach is to use screenshots or video recording. You can capture these even in headless mode, which might give you the visual feedback you need without switching modes.
Remember, each approach has trade-offs. Consider your specific use case and performance requirements when deciding which method to implement.
hey there JessicaDream12, sry to say but switching mid-session isnt possible
puppeteer doesn’t support that. you’d have to close the headless browser and open a new non-headless one. maybe try using a remote debugging port to connect to the existing session? good luck!
Unfortunately, switching from headless to non-headless mode mid-session isn’t supported in Puppeteer. The headless option is set during browser launch and can’t be changed dynamically. A workaround could be to use browser.wsEndpoint() to get the WebSocket endpoint of your current session, then close the headless browser and immediately launch a new non-headless browser connecting to that endpoint. This might preserve some state, but it’s not guaranteed to maintain everything from the original session. Alternatively, consider using a tool like Playwright which offers more flexibility in this regard.