jquery - PhantomJS - pause/resume javascript execution -
jquery - PhantomJS - pause/resume javascript execution -
i have phantomjs script i'm trying utilize in order generate video of particular website.
var page = require('webpage').create(); page.viewportsize = { width: 1280, height: 720 }; page.open('http://my-awesome-site.whatever', function() { var fps = 30; var seconds = 10; var elapsed = 0; var current = 0; takescreenshot(); function takescreenshot() { if (elapsed < seconds * 1000) { page.render('screenshot_' + (current++) + '.png'); elapsed += 1000 / fps; settimeout(takescreenshot, 1000 / fps); } else { phantom.exit(); } } });
the above script effort take 30 screenshots per sec 10 seconds, combine mp4 using ffmpeg.
the problem page.render() function not instantaneous, , not halt scripts running on page. when i'm pointing @ page using jquery animations, believe rely on settimeout, timeouts go on run while each screenshot processed. result, outputted video appears sped up.
is there way through phantomjs pause script execution? i'm hoping like:
page.pause(); page.render('screenshot_' + (current++) + '.png'); page.resume();
but sadly, don't see in api docs.
you set page.settings.javascriptenabled=false
if page looks don't depend on js much. aware need define settings before first phone call evaluated 1 time eg :
var page = require('webpage').create(); page.settings = { javascriptenabled=false }
see : http://phantomjs.org/api/webpage/property/settings.html
if doesn't fit need, need dig code of page find way stop animations (use browser's console). 1 time know need do, evaluate command in phantom.
page.open('http://my-awesome-site.whatever', function() { var stopscripts = page.evaluate(function() { // whatever need stop execution homecoming true; }); // ... take screenshots });
javascript jquery webkit jquery-animate phantomjs
Comments
Post a Comment