Browser Automation in an Electron Client: Investigating Puppeteer, Browser Reuse, and Nightmare

March 17, 2025

While developing PromptPulse, I wanted the client to do more than chat: the model should be able to operate a browser through MCP. Getting navigation, clicks, and screenshots working solved only part of the problem. Where would the browser come from? Would users need to install it separately? Could we reuse the Chromium already bundled with Electron? Those decisions would shape the experience of using the finished application.

On March 17 I was already working through Puppeteer MCP server import problems in Cursor. On March 19 I committed a server implementation to PromptPulse. This article focuses on the browser integration options I considered then. The broader story of model packaging and the MCP client remains in the development notes.12

Following the call through similar projects and a Claude Desktop example

I remember browser-use being popular and wanted to see how similar projects let a model operate a browser, with my own client in mind. I searched for mcp browser use server, then broswer use, opened the browser-use repository, and later searched for puppteer for electron to investigate using Puppeteer in an Electron project.3

I also read Nick Watson's tutorial on connecting a Puppeteer MCP server to Claude Desktop so a model could browse pages and extract information. It had users install Node.js/NPM, then configure a server launched via npx. One sentence was particularly direct:4

You will need NodeJS and NPM for this.

The tutorial gave me a complete call sequence to study. I hoped the client itself could take care of as much preparation as possible and spare users extra installation and configuration.

During implementation I had to distinguish the roles. The model proposes an operation, the client sends it to the MCP server, and the server calls the browser automation code. Controlling the browser does not teach the model when to invoke a tool. A model returning a tool call doesn't mean a browser has started correctly either.

In the March 19 implementation, I used a tool-capable Qwen2.5 model, passed it the Puppeteer tool definitions, and converted its returned calls into MCP tools/call. For this interface between model and protocol, see What Is MCP?.5

Connecting the Puppeteer MCP server to the client

I looked at the npm code page for @modelcontextprotocol/server-puppeteer 0.6.2. For my own integration, I put Puppeteer MCP server code in the backend. The March 19 commit exposed tools for navigation, screenshots, clicking, typing, selecting, hovering, and executing scripts, receiving calls via /sse and /messages.26

The project then depended on puppeteer-core and @modelcontextprotocol/sdk. It did not list @modelcontextprotocol/server-puppeteer as a dependency. Thus 0.6.2 was the code version I inspected, not the version of a server package installed by PromptPulse.6

I also had a separate puppeteer-core-try experiment. By March 17 I was debugging its MCP server in Cursor, including module imports, initialization, and tool-call timeouts. Its retained local code used puppeteer-core to launch Chrome at a specified path. Its manifest also listed @modelcontextprotocol/server-puppeteer: "^0.6.2", unlike the later PromptPulse backend integration.7

The server's ensureBrowser() started the browser on demand. Here is an excerpt of the launch options:2

browser = await puppeteer.launch({
    executablePath: '/opt/google/chrome/chrome',
    headless: false,
    slowMo: 50
});

The origin of the browser is explicit: this starts Chrome from a particular local path. Electron handles the client UI and application logic. Browser operations happen in another browser instance launched alongside it.

That matters for distribution. Knowing where Chrome is on my development machine doesn't establish that users have it installed, much less at the same path. After getting the tool-call chain working, I still had to decide how to ship or locate a browser.

I also searched for how to use pupeteer with a existing chrome and read Puppeteer issue #288, Use of already installed Chrome. The answer suggested providing executablePath to launch(), matching my implementation. It also warned about version compatibility:8

Just note that the Puppeteer API is not guaranteed to work if you use a diff version of chrome.

This reuses an installed executable but still starts a fresh browser instance. Attaching to a browser that is already running requires a separate debugging connection. That also mattered when considering reuse of Electron's browser.

Since I could point Puppeteer to an existing Chrome, I wanted to know whether installation could skip downloading a second browser. I searched for install pupetteer without chrommiun core and opened a relevant Restack page.9 This is precisely where puppeteer-core fits. It doesn't download Chrome during installation, leaving the application to supply or connect to a browser. The Puppeteer v24.0.0 installation guide explicitly distinguishes the two packages.10 Skipping the download eliminates a duplicate browser but leaves the “download the client and start using it” question unresolved when the user has no Chrome.

I also searched specifically for puppeteer-core and looked through the repository's packages/puppeteer-core/src directory.11 Moving from using the control library to inspecting its implementation, I was still focused on how the browser starts, connects, and integrates with my own client.

While debugging the experiment I encountered Attempted to use detached Frame, searched for the error, and read Puppeteer issue #12294. On March 17 I pasted the following original error into Cursor:12

McpError: MCP error -32603: Attempted to use detached Frame 'B5A7EF4E4F492735D4C4568C44D1521A'.

The error traveled back to the client through MCP, but the underlying thing to investigate was the state of the page and its Frame. Cursor suggested tracking new pages, checking whether the page reference remained valid, recreating the page on failure, and adjusting navigation waits. I no longer remember the eventual handling. Both the remaining experiment and subsequent PromptPulse commits stored pages[0] on initialization and returned that page directly, without the proposed validation and recreation logic. I later reported a tool that had executed even as the client still showed a timeout. That shows I continued investigating timeouts, not that I retested and fixed the detached Frame.1213

Issue #12294 did not provide a confirmed general fix either. In the reporter's CDP logs the maintainer saw Inspector.detached with the reason "Render process gone." and concluded that the page's renderer process had crashed in that case. Identical error text can call for different explanations, so browser logs matter before attributing the problem to navigation waits. The issue eventually closed automatically for lack of confirmation and subsequent activity. I have no corresponding crash log from my experiment. Its cause and whether it was completely resolved remain uncertain.14

Could I reuse the Chromium already bundled with Electron?

Searching for node puppeteer in electron led me to Puppeteer issue #4655. Its author wanted to use Electron's bundled Chromium and avoid an extra Chrome/Chromium executable. They also mentioned Nightmare.js. They explained:15

because chromium is already bundled into electron.

This is more specific than “Can I call Puppeteer in an Electron project?” Launching an external Chrome from Electron and connecting Puppeteer to Electron's own windows are different integrations.

In a reply, TrevorSundberg described puppeteer-in-electron, which connects to Electron over a debugging connection and handles the correspondence between an Electron BrowserWindow and a Puppeteer Page. He noted limitations of the version at the time.15 That gave me a direction to investigate, although a 2019 compatibility description did not verify the versions I was using in 2025.

Grouped by where the browser came from, these were my options:

DirectionWhat needed solvingWhere I got
Launch locally installed Chrome with PuppeteerLocate the executable and manage browser startup and page operations.Committed an implementation, then added a configurable path.
Connect Puppeteer to Electron's browser instanceEstablish a debugging connection, map windows to pages, and check compatibility with the required operations.Read the relevant issue. This approach was not used in the commits described above.
Investigate alternatives such as NightmareEvaluate suitability for shipping without browser setup.Added a milestone and a task. The work remained incomplete.

My goal was not to rank the libraries in general. I wanted a way to implement the client operations while reducing the environment preparation expected of users. Switching automation APIs would still require checking runtime distribution, window management, and whether all the necessary operations actually worked.

Nightmare made the plan; Chrome path configuration shipped first

I read vingkan's Getting Started with Nightmare.js and the page extraction section in Nightmare's README. The Gist combined goto, type, click, and evaluate to perform browser operations and return page results to the script. It helped me see how another automation interface would execute an operation and get its result.16

The README says of evaluate:

Useful for extracting information from the page.17

It executes a function in the page context and returns its value to the caller. “Extract from the Page” also covers determining whether elements exist or are visible, and page events. These capabilities related to tools I wanted to give the model. The README also says Nightmare uses Electron underneath. This alone did not mean it automatically took over an existing client window; the integration still needed verification.17 I looked through its lib source directory, including actions.js, ipc.js, nightmare.js, preload.js, and runner.js.18

Following the dependencies in Nightmare's package.json led me to rimraf: "^2.4.3", and I opened rimraf's npm page.19 It recursively removes files and directories, providing functionality like rm -rf while handling cross-platform differences. I came across it incidentally while reading the dependencies.20

Nightmare did make it into the project plan. On March 21 I created a milestone called “support no chrome core with nightmarejs” and filed issue #4, “support no need of chrome path,” under it. I wanted users to be able to omit the Chrome path.21

Meanwhile I made the existing implementation configurable. Commit b360a06 on March 23 added a Chrome path settings UI and read chromePath from user configuration at launch. It kept the original Linux path as a fallback. The change let people specify a browser location, but didn't yet produce a configuration-free experience.22

I didn't continue developing the project. Its board retained the state at which I left it:23

TaskBoard statusScope
#4: support no need of chrome pathBacklogRemove the Chrome path requirement, associated with the Nightmare milestone.
#12: finish preliminary MCP setting viewDoneSettings including the Chrome path, MCP configuration, tool status, and API configuration.

The cards describe different levels of completion. The settings interface was complete while configuration-free operation remained a later goal. Nightmare stayed in research and planning; the browser automation actually delivered still depended on local Chrome.

For the “download and use” client I wanted, discovering and calling MCP tools was only one layer. Models, tool runtimes, and external programs such as the browser each needed a clear distribution strategy. This also came up in my later independent Node runtime experiment, described in Running Local ONNX Models in Electron with a Separate Node Sidecar.

References

Footnotes

  1. CaiBorui. (2025, March 17). Fixing ES Module and CommonJS Conflicts; Converting Static Imports to Dynamic Imports [private Cursor conversation retained by the author]. Concerns PromptPulse/desktop/express_server/puppteer_server/index.js. The adjacent assistant replies were recorded at 13:31–13:39 Beijing time. The user requested conversion from static to dynamic imports. ↩

  2. CaiBorui [S2thend]. (2025, March 19). PromptPulse Puppeteer MCP server [historical code, commit f0af43a, tool definitions, ensureBrowser, and SSE routes]. GitHub. https://github.com/S2thend/PromptPulse/blob/f0af43a68e3118dfaca2ff46a89ee8182e2211de/desktop/express_server/puppteer_server/index.js ↩ ↩2 ↩3

  3. CaiBorui. (2026, November 17). Recollections and browsing trail for browser automation research [historical material supplied by the author]. mcp browser use server → broswer use → browser-use/browser-use → puppteer for electron. The author recalls looking into similar implementations because browser-use was popular. The order follows the supplied history; individual visit dates are unknown. ↩

  4. Watson, N. (2024, December 10). Tutorial: Use Claude Desktop, MCP, Puppeteer to Automatically Extract Data From The Web, “2. Install NodeJS/NPM,” first paragraph; “4. Update Claude Desktop Config”; “6. Take it for a spin!” SureScale.ai, Medium. https://medium.com/surescale/tutorial-use-claude-desktop-mcp-puppeteer-to-automatically-extract-data-from-the-web-b5692dbdcd6e . Access date: June 8, 2025. ↩

  5. CaiBorui [S2thend]. (2025, March 19). PromptPulse MCPChatView [historical code, commit 286488c, model requests and tool-call loop]. GitHub. https://github.com/S2thend/PromptPulse/blob/286488c7819a7f6e8e9dd4ecf005c99c42d41dc5/web/src/views/MCPChatView.jsx . A code comment preserves a sample qwen2.5:1.5b response returning puppeteer_navigate with Google as the target, distinct from the 3B model in the actual request configuration. ↩

  6. Model Context Protocol contributors. (n.d.). @modelcontextprotocol/server-puppeteer, version 0.6.2 [npm code page inspected by the author]. npm. https://www.npmjs.com/package/@modelcontextprotocol/server-puppeteer/v/0.6.2?activeTab=code . For actual integration and dependencies, see CaiBorui [S2thend]. (2025, March 19). PromptPulse desktop/package.json. ↩ ↩2

  7. CaiBorui. (2025, March 17). Fixing MCP Server Implementation Issues [private Cursor development conversation retained by the author]. Created at 12:48:19 Beijing time. The user's error path was electron_play/puppeteer-core-try/mcp_server/index.js; later questions described a timeout despite tool execution. See the retained local puppeteer-core-try/package.json and mcp_server/index.js (ensureBrowser). The local files describe the surviving implementation without establishing that every line was written during that chat. ^0.6.2 is a dependency range. Checked November 17, 2026. ↩

  8. bricss. (2017, August 16). Use of already installed Chrome [issue #288]. GitHub. https://github.com/puppeteer/puppeteer/issues/288 . ebidel's same-day reply gives the executablePath example and compatibility caveat; the quote is from the first paragraph after the example: https://github.com/puppeteer/puppeteer/issues/288#issuecomment-322822607 . Visit trail: how to use pupeteer with a existing chrome → issue #288. Access date: June 8, 2025. ↩

  9. Restack. (n.d.). Installing Puppeteer without downloading Chromium [visited URL, descriptive title; original text unavailable]. https://www.restack.io/p/puppeteer-answer-install-puppeteer-without-chromium . Visit trail: install pupetteer without chrommiun core → Restack. Access date: June 8, 2025. The page was inaccessible upon checking November 17, 2026, and a Wayback availability lookup returned no snapshot. No specific steps are attributed to it. ↩

  10. Puppeteer contributors. (n.d.). Installation [v24.0.0 documentation on puppeteer and puppeteer-core]. GitHub. https://github.com/puppeteer/puppeteer/blob/puppeteer-v24.0.0/docs/guides/installation.md . The fixed-version documentation verifies the technical explanation; it does not establish that this URL was visited at the time. Access date: June 8, 2025. ↩

  11. Puppeteer contributors. (n.d.). puppeteer-core/src [source directory]. GitHub. https://github.com/puppeteer/puppeteer/tree/main/packages/puppeteer-core/src . The author supplied a separate puppeteer-core search, without specifying navigation order or particular files read. The main branch link is not a 2025 snapshot. Access date: June 8, 2025. ↩

  12. CaiBorui. (2025, March 17). Fixing MCP Server Implementation Issues [private Cursor conversation retained by the author; detached Frame error and two later timeout questions]. The original stack includes Client._onresponse, _transport.onmessage, and _eventSource.onmessage. The adjacent assistant reply's clientRpcSendTime was 13:02:08 Beijing time. The user message has no separate timestamp. Suggested changes do not establish adoption. Visit trail: attempt to use detached frame → https://github.com/puppeteer/puppeteer/issues/12294 . Exact visit time unknown. Local records checked November 17, 2026. ↩ ↩2

  13. CaiBorui [S2thend]. (2025, June 5). PromptPulse Puppeteer MCP server [historical code, commit 610cd8d, ensureBrowser]. GitHub. https://github.com/S2thend/PromptPulse/blob/610cd8db5780ce2a6d60e5c3c8fbdbad5a891ee3/desktop/express_server/puppteer_mcp_server/index.js . Checks covered the first March 19 commit through the file's final June 5 change and the local puppeteer-core-try experiment. No corresponding recovery logic or clear retest conclusion was found. ↩

  14. JayKaku. (2024, April 18). Error: Attempted to use detached Frame [issue #12294]. GitHub. https://github.com/puppeteer/puppeteer/issues/12294 . On April 22, OrKoN identified a renderer crash from the CDP logs: https://github.com/puppeteer/puppeteer/issues/12294#issuecomment-2068576533 . On July 19 a bot closed the unconfirmed issue: https://github.com/puppeteer/puppeteer/issues/12294#issuecomment-2238993864 . That case originally used Puppeteer 22.6.4 and does not establish the same environment as mine. Access date: June 8, 2025. ↩

  15. s0thl. (2019, July 2). Is it possible to run puppeteer on electron window? [issue #4655, opening paragraph, quote from its final sentence]. GitHub. https://github.com/puppeteer/puppeteer/issues/4655 . See TrevorSundberg. (2019, August 8). Reply on puppeteer-in-electron, debugging connections, and mapping BrowserWindow to Page; Sundberg, T., & contributors. (n.d.). puppeteer-in-electron README. Compatibility remarks concern the version at the time. Visit trail: node puppeteer in electron → issue #4655. Access date: June 8, 2025. ↩ ↩2

  16. vingkan. (n.d.). Getting Started with Nightmare.js [instructions.md, scraper.js, and package.json]. GitHub Gist. https://gist.github.com/vingkan/5f334786aef59601534feaca77efecac . The sample's package.json declares nightmare ^2.10.0, a reading-material version rather than a PromptPulse dependency. Access date: June 8, 2025. ↩

  17. Nightmare contributors. (n.d.). Nightmare README [introduction, “.evaluate(fn[, arg1, arg2,...])”, and “Extract from the Page”]. GitHub. Original entry: https://github.com/segment-boneyard/nightmare#extract-from-the-page ; file used to verify: https://github.com/segment-boneyard/nightmare/blob/master/Readme.md . Quotation from the opening paragraph of the evaluate description. Access date: June 8, 2025. ↩ ↩2

  18. Nightmare contributors. (n.d.). lib [source directory]. GitHub. https://github.com/segment-boneyard/nightmare/tree/master/lib . Access date: June 8, 2025. ↩

  19. Nightmare contributors. (n.d.). package.json [version 3.0.2, rimraf in dependencies]. GitHub. https://github.com/segment-boneyard/nightmare/blob/master/package.json . Readable source: https://raw.githubusercontent.com/segment-boneyard/nightmare/master/package.json . Access date: June 8, 2025. ↩

  20. Schlueter, I. Z., & rimraf contributors. (n.d.). rimraf [npm package page]. npm. https://www.npmjs.com/package/rimraf . Functionality checked in the introduction, API, and CLI sections of the v2.4.3 README: https://github.com/isaacs/rimraf/blob/v2.4.3/README.md . Access date: June 8, 2025. ↩

  21. CaiBorui [S2thend]. (2025, March 21). support no chrome core with nightmarejs [milestone #1]. GitHub. https://github.com/S2thend/PromptPulse/milestone/1 ; support no need of chrome path [issue #4]. https://github.com/S2thend/PromptPulse/issues/4 . Created at 16:39:56 and 16:40:45 Beijing time respectively; the issue was assigned to the milestone. ↩

  22. CaiBorui [S2thend]. (2025, March 23). feat: :wrench: add feature set chrome path config [commit b360a06, backend browser startup configuration and MCPConfigView]. GitHub. https://github.com/S2thend/PromptPulse/commit/b360a0650a7cc68fba325dda4f805ff5a9149de9 ↩

  23. CaiBorui [S2thend]. (n.d.). PromptPulse project board [GitHub Projects #3, author-provided HTML copy]. GitHub. https://github.com/users/S2thend/projects/3 . The copy places #4 in Backlog and #12 in Done. The latter task includes setting the Chrome path: https://github.com/S2thend/PromptPulse/issues/12 . The author supplied it on November 17, 2026, and explained that work had not continued, leaving the board in its 2025 state. This does not establish a precise stopping date. ↩

© 2025 borui. All rights reserved. This content may be freely reproduced, displayed, modified, or distributed with proper attribution to borui and a link to the article: borui (2025-03-17). Browser Automation in an Electron Client: Investigating Puppeteer, Browser Reuse, and Nightmare. https://caiborui.com/blog/2025-03-17-zh-electron-browser-automation-entrans

@misc{borui2025-1b04fcbf,
  author = {borui},
  title = {{Browser Automation in an Electron Client: Investigating Puppeteer, Browser Reuse, and Nightmare}},
  year = {2025},
  publisher = {borui's blog},
  url = {https://caiborui.com/blog/2025-03-17-zh-electron-browser-automation-entrans}
}