question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Node is detached from document

See original GitHub issue

GOAL: I currently am building a script that checks the last few messages in each conversation to see whether i can “mark as done” from a company account. The whole can loop through the list of people and get the messages but at soon as Its time to “mark a conversation as done” the next iteration of the loop breaks because of a “node is detached from the document”

  • Puppeteer version: Chrome/83.0.4103.0
  • Platform / OS version: Chromium: Version 83.0.4103.0 (Developer Build) (64-bit)
  • URLs (if applicable): https://business.facebook.com/
  • Node.js version: v13.12.0

What steps will reproduce the problem?

  1. Log in to a FB business account
  2. mark more than 2 Facebook conversations as done using a certain ID

Please include code that reproduces the issue.

for (let i = 0; i < section.length; i++) {
      try {
        await section[i].click();
        await page.waitForSelector('._suc._su6._5bpf');
        await page.$eval('._suc._su6._5bpf', form => form.click() ); // Here is where the issue happens
  } catch (err) {
    if ((err.message == 'Node is either not visible or not an HTMLElement' ||
      err.message == 'Node is detached from document')) {
        delay(2000);
    } else {
      stop = true;
    }
    console.log(Error(err), err.message, err.number);
  }
}

[Screenshots] Screenshot 2020-06-17 at 13 49 26 This selector will only have one occurrence for each page you are on so the ('._suc._su6._5bpf') only has once occurrence. until the conversation moves to another person in the list like this: as it iterates:

Screenshot 2020-06-17 at 13 54 35

What is the expected result?

I expect the for loop to continue checking the conversations

What happens instead?

Error: Error: Node is detached from document at /Users/mahirhiro/headless-chrome/index.js:61:17 …

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:10

github_iconTop GitHub Comments

5reactions
KevinHCHcommented, May 3, 2021

I had the same problem, the error was the element was available inside the HTML, but not was available for puppeter, because puppeteer needs to “see” or “needs to have something visible” to touch it or click it. The solution was to click through HTML instead of puppeter

//puppeteer handler
await row_element.click()

//html handler (solution)
await page.evaluate((element) => {
  element.click()
}, row_element)
2reactions
mahirhirocommented, Mar 6, 2021

@t1a2l I couldn’t find a fix using puppeteer so I switched to selenium haha.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ElementHandle click method get Error: Node is detached from ...
I've encountered this problem too on a different site. The click method has a built in function that enables puppeteer to scroll to...
Read more >
Looping through page links puppeteer doesn't return values ...
That seems to work, however, it causes this error our error Error: Node is detached from document on the second loop?
Read more >
Solving The Element Is Detached From DOM Error In Cypress
The "element is detached from DOM" is a sign of a problem, not the problem itself! There is a variety of ways the...
Read more >
Node.isConnected - Web APIs - MDN Web Docs
The read-only isConnected property of the Node interface returns a boolean indicating whether the node is connected (directly or indirectly) to a Document ......
Read more >
Debug DOM memory leaks with the Detached Elements tool
Use the Detached Elements tool in the Microsoft Edge DevTools to find and fix DOM memory leaks.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found