Hey everyone! I’m working on a project using Puppeteer and I’m trying to figure out how to launch a browser in incognito mode. Right now, I’m connecting to a browser using a WebSocket endpoint, but I want the whole session to be incognito from the start.
I’ve tried using createIncognitoBrowserContext(), but it seems like this just creates an incognito tab within the main browser session. What I’m after is a completely separate incognito browser instance.
I’ve also seen that you can pass --incognito as an argument when launching the browser, like this:
I’ve had success launching a standalone incognito session with Puppeteer by using the --incognito flag, as you mentioned. However, I found that combining it with a few other arguments gives more reliable results:
The --no-first-run and --no-default-browser-check flags help prevent any unwanted dialogs or settings from interfering with your incognito session. Additionally, make sure you’re closing the browser properly after use to avoid any lingering processes. This approach has worked well for me in projects requiring a fresh, isolated browsing environment for each run.
I’ve dealt with this issue before, and here’s what worked for me. Instead of using --incognito, I found that creating a new user data directory for each session gives you more control and isolation:
This approach creates a fresh profile every time, effectively giving you an incognito-like experience. Remember to clean up the temporary directories after you’re done to avoid cluttering your system. It’s a bit more work, but it gives you full control over the browser environment and ensures complete separation between sessions.