Wait for DOM content before snapping
See original GitHub issueIt 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:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.
@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 (likeshouldEndCapture
) 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.