kevva / screenshot-stream

Capture screenshot of a website and return it as a stream
MIT License
236 stars 38 forks source link

problem in using the script option #43

Open ghost opened 7 years ago

ghost commented 7 years ago

Hi,

I would like to click a button before capturing the screen which I add a script option as follows:

const Pageres = require('pageres');

const pageres = new Pageres({
    delay: 2,
    script: "document.querySelector('.coreSpriteRightChevron').click();"
})
    .src('https://www.instagram.com/p/BWh3WDKh5c5/', ['1600x1200'], {crop: true})
    .dest(__dirname)
    .run()
    .then(() => console.log('done'));

but it doesn't work. I tried to change the delay time, put it into different part of the script like in src or run but doesn't work too. Would you please help on this?

medikoo commented 7 years ago

@kevva I just approached very same problem.

From what I investigated, problem is that screenshot is grabbed immediately after script invocation (delay option is used for prior logic). Therefore if script action demands some time to propagate (as e.g. click), then there's no chance to achieve the effect.

I can propose as PR with w e.g. scriptDelay option, that will force eventual delay between script evaluation and screenshot grap. Let's just first agree that's best solution for that (?)