Puppeteer: At least one query method must be implemented.
A custom query handler registration has neither queryOne nor queryAll.
A custom query handler registration has neither queryOne nor queryAll.
Error message
At least one query method must be implemented.
How this error happens
registerCustomQueryHandler needs queryOne or queryAll. An empty object provides no way to find an element.
The snippets use the imported Puppeteer class for its static query-handler methods. The fix uses the same import.
import {
Puppeteer,
} from "puppeteer";
Puppeteer.registerCustomQueryHandler(
"custom",
{}
);
How to fix
Implement at least one query method. Puppeteer can derive the other method from it.
Puppeteer.registerCustomQueryHandler(
"custom",
{
queryOne: (root, selector) => {
return root.querySelector(selector);
},
}
);
Things to keep in mind
Query functions run in the browser. They cannot read variables from your Node.js closure.