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

218
Views
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 answers
Answer question

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 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!