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

219
Visualizações
console.log logging empty values unless specific value is specified

I am using Node.js and Puppeteer and have it set up to load a specific page. This page renders new elements every second and I am adding a MutationObserver to listen and have a function trigger when new elements are added.

If I for example try getItem(mutation) it will log {}, an empty object
But if I try to getItem(mutation.addedNodes[0].textContent) it will log 'NewElement', which is the text content of the new element.

Also trying anything between mutation all the way to mutation.addedNodes[0].textContent results in empty objects/arrays.

Why does the first example not log anything, the object has values since I can reach them by being more specific. Why does it not log the values it holds and the structure of the object.

const runPuppeteer = async (url: string) => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.setViewport({ width: 1920, height: 1080 })
  await page.goto(url);

  await page.exposeFunction('getItem', (a: any) => {
    console.log(a)
  })

  await page.evaluate(() => {
    let observer = new MutationObserver((mutations) => {
      for (const mutation of mutations) {
        getItem(mutation.addedNodes[0].textContent) // <--- My question
      }
    })
    observer.observe(document.querySelector('#chatDiv'), { attributes: false, childList: true, subtree: true })
  })
}

let myPage = 'http://localhost:3000/home'
runPuppeteer(myPage)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Not all properties of all objects will print with console.log, particularly with builtins. If you want to know all the properties on an object, you can try Object.keys(o) or Reflect.ownKeys

There are also serialization libraries and "objectify" libraries that will try to turn a complex class instance into an explicit json-like Object.

Sometimes classes will have getters, a number will be wrapped as an object, objects will be proxied, etc, so in general the console.log output can be extremely incomplete

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