javascript - PhantomJS- open page with LocalStorage by default -


i'm using phantomjs generated source of web page after javascript dom manipulations have taken place. web page has <body> , nothing else.

important: web page uses browser's localstorage generate page.

i want change localstorage in phantomjs before opening page.

app.js:

var page = require('webpage').create();  page.open("https://sample.com") settimeout(function(){     // want save         page.render("screenshoot.png")       // can access content using jquery     var fbcomments = page.evaluate(function(){         return $("body").contents().find(".content")      })      phantom.exit(); }, 1000) 

localstorage particular domain available when open page on domain. can

  1. open url on domain you're interested in,
  2. change localstorage according needs,
  3. open target url on same domain.

this can this:

page.open("https://sample.com/asdfasdf", function(){     page.evaluate(function(){         localstorage.setitem("something", "whatever");     });      page.open("https://sample.com", function(){         settimeout(function(){             // want save                 page.render("screenshoot.png")               // can access content using jquery             var fbcomments = page.evaluate(function(){                 return $("body").contents().find(".content")              })              phantom.exit();         },1000)     });     }); 

it's possible not open full page in step 1. can use dummy page url.

page.setcontent("", "https://sample.com"); // doesn't open page  page.evaluate(function(){     localstorage.setitem("something", "whatever"); });  page.open("https://sample.com", function(){     settimeout(function(){         // want save             page.render("screenshoot.png")           // can access content using jquery         var fbcomments = page.evaluate(function(){             return $("body").contents().find(".content")          })          phantom.exit();     }, 1000) });     

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -