Can I run a headless browser instance with Puppeteer inside Electron application?

I’m working with Puppeteer integrated into my Electron app and I need to know if there’s a way to launch a headless browser session. Right now I’m creating the browser connection using this approach:

const browserInstance = await pie.connect(electronApp, puppeteer);
const currentPage = await pie.getPage(browserInstance, mainWindow);

The issue is that this creates a visible browser window, but I want to run it in headless mode for background processing. Is there a configuration option or different method I should use to achieve this? I’ve tried looking through the documentation but haven’t found a clear answer about headless mode specifically for Puppeteer-Electron integration.

The puppeteer-in-electron package doesn’t support headless mode because it’s meant to control your existing Electron renderer process. You need a hybrid approach - keep your main Electron app running normally but spawn separate headless browser instances for background work. I’ve done this by creating a service in my main process that manages headless Puppeteer instances using the standard puppeteer.launch() with headless enabled. Treat these as completely separate from your Electron UI - they run their own Chrome instances. Use Electron’s IPC messaging to send tasks to these background browsers and get results back in your renderer process. This gives you the best of both worlds without forcing the library into something it wasn’t designed for.

You’re mixing two different approaches here. pie.connect() controls an existing Electron window - that’s why you see the visible browser. For true headless operation, launch a separate Puppeteer instance alongside your Electron app instead of trying to make the Electron renderer headless. I hit this same issue last year and ended up using puppeteer.launch({ headless: true }) to create a completely separate browser instance for background tasks. This runs independently from your Electron app and handles all scraping or automation work invisibly. You can communicate between your Electron main process and the headless browser using IPC channels to pass data back and forth. Cleaner separation and gives you the headless functionality you need.

yup, you’re right about pie - it ain’t meant for headless. i use puppeteer.launch() in the main process to handle background stuff while keepin the electron ui separate. just start headless instances when needed, then close em after. perfect for scraping without messing up the app.