Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

437
Views
Javascript Evaluation failed: ReferenceError: parameter is not defined

I am writing a function in javascript:

const getContent = async (page, element) => {
  const contentStr = await page.evaluate(() => {
    const contentEl = document.querySelector(element);
    const content = contentEl?.getAttribute("content");

    if (content != null && content.length > 0) {
      return content;
    } else {
      return null;
    }
  });
  return contentStr;
};

When executing this function, I am getting an error:

Error: Evaluation failed: ReferenceError: element is not defined

Can anyone help?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is the function signature of puppeteer's page.evaluate

page.evaluate(pageFunction[, ...args])

As you can see you can pass arguments to the pageFunction as additional paramateters when calling page.evaluate. The reason this is necessary is because one execution context ist node js while the other one is the chromium browser and those contexts run in different processes and don't share memory except when you pass variables via the puppeteer api.

So in your case this might work (not tested):

const getContent = async (page, element) => {
  const contentStr = await page.evaluate((element) => {
    const contentEl = document.querySelector(element);
    const content = contentEl?.getAttribute("content");

    if (content != null && content.length > 0) {
      return content;
    } else {
      return null;
    }
  },element);
  return contentStr;
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!