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.

Wait for DOM content before snapping

See original GitHub issue

It would be great if it was possible to only start taking the screenshots once some specific content was on the DOM. Puppeteer has a waitForSelector function (docs), however I’ve not had success implementing this, I imagine this is because the content I am waiting for is rendered by JS.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Asheboycommented, Sep 23, 2019

@tungs I’ve put an implementation of what I needed here. I went down the route of only capturing while a selector was on the DOM. It means that the webpage can have more control over the start and end times of the capture.

Happy to make changes and submit a PR, shoot over any criticism.

0reactions
tungscommented, Apr 23, 2021

@RhinoW, I’m on the fence about this, though I’m leaning towards the overall idea; the implementation seems straightforward and generally useful, though it feels a little feature bloaty.

If I do implement it, it would probably be as two functions: a start function (like shouldStartCapture) that would take page as an argument and resolve to true to begin capturing and an end function (like shouldEndCapture) that would take page as an argument and resolve to true to prematurely end capturing. The function names might need a little tweaking to make it clear that virtual time is being incremented.

This should give you the flexibility to check for a range of things (e.g. see if an element exists or a global variable is set to a certain value).

Would this work for your use case? I realize that this would require specifying a function instead of a string, so it can be less friendly than Asheboy’s implementation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to wait for page to finish loading all content before ...
First of all, you should use a TreeWalker to traverse the DOM ... How to wait for page to finish loading all content...
Read more >
For how long does the google bot wait after document ready ...
Googles bot will stick around as long as it needs to unless it times out or is stupidly slow. Regardless what the content...
Read more >
BREAKING: make waitForDomChange accept a callback #376
I'd like to think of waitForDomChange as a variant to wait which re-runs a callback whenever the DOM changes rather than arbitrarily every...
Read more >
Solving The Element Is Detached From DOM Error In Cypress
// application starts doing something · // now the test should wait for the app · // before calling another command · //...
Read more >
Javascript --- wait for DOM or element to load. - Nikita Kazakov
Javascript is asynchronous and a common pain-point is running a script before a DOM element on the page has loaded.
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