(Created on )

Puppeteer: Cannot register over existing handler: {value}

A custom query handler name is already registered.


A custom query handler name is already registered.

Error message

Cannot register over existing handler: {value}

{value} is replaced by the value shown in your error message.

How this error happens

A handler name can be registered only once. Running setup twice in a test suite can collide with the earlier registration.

The snippets use the imported Puppeteer class for its static query-handler methods. The fix uses the same import.

import {
    Puppeteer,
} from "puppeteer";

const handler = {
    queryOne: (root, selector) => {
        return root.querySelector(selector);
    },
};

Puppeteer.registerCustomQueryHandler(
    "custom",
    handler
);

Puppeteer.registerCustomQueryHandler(
    "custom",
    handler
);

How to fix

Own registration in one setup phase. If setup may run repeatedly, check the registered names first.

if (!Puppeteer.customQueryHandlerNames().includes("custom")) {
    Puppeteer.registerCustomQueryHandler(
        "custom",
        {
            queryOne: (root, selector) => {
                return root.querySelector(selector);
            },
        }
    );
}

Things to keep in mind

Checking the name does not verify that an existing handler has the implementation you expect.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →