javascript - Phantomjs using a local file with page.includeJs? -
javascript - Phantomjs using a local file with page.includeJs? -
i using phantomjs screenshot webpage. library calls hosted jquery file inject jquery functionality in page dom allow manipulations. seen here: http://phantomjs.org/api/webpage/method/include-js.html
the code looks this:
if ( loaded ) { page.includejs("http://code.jquery.com/jquery-1.8.3.min.js", function() { . . .
i don't want create external phone call js because (a) it's slower , (b) not reliable. utilize local re-create , set path such not loading in.
page.includejs("assets/javascript/jquery.min.js", function() { . . .
what problem here? why path not working expect to? function page.includejs
not allow relative paths?
according documentation function includes script given url needs accessible hosted page. local path not accessible on remote host (relative nor absolute) need inject script injectjs
instead.
edit: here code used testing:
var page = require('webpage').create(); page.open("http://ipecho.net/", function(status) { if ( status === "success" ) { if (page.injectjs("jquery.min.js")) { var h1 = page.evaluate(function() { homecoming $("h1:eq(0)").css({fontsize: 10, color: "red"}).text(); }); console.log(h1); } } page.render("test.png"); phantom.exit(); });
code can injected same way jquery , work sure. remember evaluate()
limitations (but not big deal in case):
note: the arguments , homecoming value evaluate function must simple primitive object. rule of thumb: if can serialized via json, fine.
closures, functions, dom nodes, etc. not work!
edit: filepath problem: check working directory. using relative paths can tricky because of suggest utilize absolute. webpage.librarypath
need. hope helped now.
javascript phantomjs
Comments
Post a Comment