Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

438
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda