How to run puppeteer in visible mode while keeping no-sandbox flag

I’m working with puppeteer and need to start it using the no-sandbox argument for my environment to work properly.

Currently I’m using this code:

const webBrowser = await puppeteer.launch({args: ['--no-sandbox']});

This works fine but now I want to see the browser window while debugging my scripts. I tried adding the headless option like this:

const webBrowser = await puppeteer.launch({args: ['--no-sandbox']
headless: false});

But this gives me an error and doesn’t work at all. I think there’s something wrong with my syntax but I can’t figure out what. How can I combine both the no-sandbox argument and the headless false option in the same launch configuration? Any help would be great.

you’re missing a comma after the args array! should be {args: ['--no-sandbox'], headless: false} - the comma separates the two options in the object. common mistake, happens to everyone.

You’re getting a syntax error because your object formatting is wrong. When you pass multiple options to puppeteer.launch(), you need commas between each property:

const webBrowser = await puppeteer.launch({
  args: ['--no-sandbox'],
  headless: false
});

I’ve used this setup for months in my testing environment when sandbox restrictions mess things up. Just make sure you’ve got proper JavaScript object syntax with commas between properties. You can throw in other debugging options like slowMo: 100 or devtools: true the same way if you need them.

The syntax error happens because you’re missing a comma in your options object. Here’s the fix:

const webBrowser = await puppeteer.launch({
  args: ['--no-sandbox'],
  headless: false
});

I’ve run puppeteer in similar restricted environments where no-sandbox is required. When you combine these options, the browser opens normally but behaves a bit differently than sandboxed mode. Just heads up - no-sandbox disables Chrome’s security sandbox, so be careful what sites you test against when debugging with the visible window.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.