Dev.to WebDev 🛠 Dev 👁 0 📖 4 min read

My Puppeteer container couldn't find Chrome, and the run charged its fee anyway 🔑

A lock file from my laptop, a base image that floats, and a fee charged one step too early. Hi! I build small data tools that run as Apify Actors, serverless jobs that people pay for per result. I recently shipped a

My Puppeteer container couldn't find Chrome, and the run charged its fee anyway 🔑

A lock file from my laptop, a base image that floats, and a fee charged one step too early.

Hi! I build small data tools that run as Apify Actors, serverless jobs that people pay for per result.

cover-chrome-mismatch.gif

I recently shipped a new one. It opens short video pages in headless Chrome through Puppeteer, takes the audio, and turns it into a transcript. Every local test passed. The first run in the cloud lasted 4 seconds.

💥 The error

Error: Could not find Chrome (ver. 158.0.8127.88). This can occur if either
 1. you did not perform an installation before running the script (e.g. `npx puppeteer browsers install chrome`) or
 2. your cache path is incorrectly configured (which is: /home/myuser/.cache/puppeteer).

The container did have Chrome in it. It just wasn't version 158.

🔍 Why it passed on my laptop

Two things were true at once.

My laptop never used Puppeteer's own Chrome. For local runs I pointed Puppeteer at the browser I already had:

launchOptions: {
    headless: true,
    executablePath: process.env.CHROME_PATH || undefined,
},

With CHROME_PATH set to Edge, Puppeteer skips its own browser cache completely. So every local test checked my code, and none of them checked which Chrome the container would have.

The container's Chrome and Puppeteer came from two different places. The Dockerfile started from a base image that ships Node, Puppeteer and a matching Chrome:

FROM apify/actor-node-puppeteer-chrome:20

COPY package*.json ./
RUN npm install --omit=dev --omit=optional

And package.json said:

"puppeteer": "*"

I wrote * thinking it meant "whatever the image already has". But package*.json also copies package-lock.json, and my lock file came from my laptop, where * had resolved to the newest release: Puppeteer 25.19.0. That version looks for Chrome 158. The image's Chrome was built for an older Puppeteer.

📜 The build log had already said so

The build passed, so I didn't read it. I should have:

npm warn EBADENGINE Unsupported engine {
npm warn EBADENGINE   package: '[email protected]',
npm warn EBADENGINE   required: { node: '>=22.12.0' },
npm warn EBADENGINE   current: { node: 'v20.20.2', npm: '10.8.2' }
npm warn EBADENGINE }
...
added 41 packages, removed 44 packages, changed 88 packages

Two clues are in there. Puppeteer 25 wants Node 22.12 or newer, and the image ran Node 20. And "removed 44, changed 88" means the install replaced a big part of what the image came with. Neither one fails a build, so it ended green.

🔧 The fix: pin both sides to the same number

The same image is also published under tags that name both versions, for example 22-25.19.0 (Node 22, Puppeteer 25.19.0), next to floating tags like 22 and 20. So I pinned the image and the library to the same version:

FROM apify/actor-node-puppeteer-chrome:22-25.19.0
"engines": { "node": ">=22.12.0" },
"dependencies": { "puppeteer": "25.19.0" }

The next build log had zero EBADENGINE lines, and the next cloud run finished in 12 seconds with a transcript in it.

Floating tags like :20 and * are fine on their own. The trouble starts when two of them float apart. Now, when I bump one, I bump the other in the same commit.

💸 The second bug: the fee came first

The tool charges per transcript, plus a small fee per run that covers starting the browser. Here's where that fee was charged:

if (requests.length) {
    await Actor.charge({ eventName: 'run-start' });
    await crawler.run(requests);
}

It came before the crawler started, and so before Chrome was launched. The failed run was my own test, so the only person charged was me. But a customer would have paid $0.05 for a browser that never opened.

The fix moves the charge to the first moment the run has actually done something: the first page has loaded and its data has been found.

let runFee;
const chargeRunFee = () => (runFee ??= Actor.charge({ eventName: 'run-start' })
    .then((r) => !(r?.eventChargeLimitReached && !r.chargedCount)));

// In the request handler, after the page's data has been found:
if (!(await chargeRunFee())) {
    await crawler.autoscaledPool?.abort(); // the buyer's cost limit doesn't cover the fee
    return;
}

Up to three pages load at the same time, so several handlers can reach this line together. ??= makes sure only the first one starts the charge, and the others wait on the same promise. That way they all get the same answer to "did the fee go through, or did we hit the buyer's spending limit?" A plain boolean flag would stop the double charge, but the other handlers wouldn't know the result.

Now a run that can't start the browser, or can't load a single page, costs the buyer nothing.

✅ What I'd tell myself before starting

  • If your local runs use a different browser than the container, your local tests aren't testing the browser install. Run one test with the container's own browser before you ship.
  • Read the warnings in a green build log. EBADENGINE told the whole story before the first run started.
  • Pin the base image and the library to the same version, and change them together.
  • Charge (or count, or bill) after the first piece of real work succeeds, not at startup.
📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.