Puppeteer page.evaluate() – error when passing object reference as function argument

  ecmascript-6, javascript, node.js, puppeteer

I am working on a Puppeteer web-scraper, in which the Page.evaluate function takes an object of global variables as its argument (to use them in the DOM context)… The following works fine:

await page.evaluate(({parameter_A,
    parameter_B,
    parameter_C}) => {
    some code
}, {parameter_A,
    parameter_B,
    parameter_C}
);

However, when I try to define a separate object to hold the arguments (to avoid errors, since they must be stated twice), it does not work and throws a ReferenceEror …

let searchParameters = {
    parameter_A,
    parameter_B,
    parameter_C,
};

await page.evaluate((searchParameters) => {
    some code
}, searchParameters);

However, when I try to define a separate object to hold the arguments (to avoid errors, since they must be stated twice), it does not work and throws a ReferenceError … I have tried variations such as turning searchParameters into an array, destructuring, etc. to no avail.

Any help much appreciated!

Source: Ask Javascript Questions

LEAVE A COMMENT