johntitus / node-horseman

Run PhantomJS from Node
MIT License
1.45k stars 125 forks source link

Wait for API call to finish #286

Closed archieherbias closed 7 years ago

archieherbias commented 7 years ago

I am accessing a webpage that has an API call when it's mounted. What I want is that I want to wait after the API call has finished/responded then create a PDF after that.

What should I do to wait for the page to get updated? The webpage is built on Reactjs.

My code is something like this.

const horseman = new Horseman()
horseman
.open('http://something/id')
.waitFor(function waitForValue(selector, initial) {
    return $(selector).text() !== initial
}, '#id', '0.00', true)
.pdf('name.pdf', {
    format: 'A4',
    orientation: 'portrait',
    margin: '0in'
})
.close()
awlayton commented 7 years ago

I am not familiar with React, so I do not know how you can go about determining when the page is "ready" for you.

I image you will need to find something specific to the particular page and how it changes. Using waitFor like you are is probably on the right track.

archieherbias commented 7 years ago

Thanks for your response @awlayton but I switched to using nightmare and it seems it has tools for react as well.