Wednesday, 15 June 2011

Why is PhantomJS rejecting the JavaScript in my HTML file? -



Why is PhantomJS rejecting the JavaScript in my HTML file? -

for sake of development, process.js looks this:

var page = require('webpage').create(); var scheme = require('system'); var fs = require('fs'); var file = fs.open(system.args[1], 'rb'); // tried 'r' page.content = file.read; // page.evaluate(function(){ // }); // commented out know evaluate() not causing problem system.stdout.write(page.content); page.close phantom.exit();

i'm calling command line using phantomjs gem ruby:

[1] pry(main)> require 'tempfile' => false [2] pry(main)> file = tempfile.new("foo") => #<file:/var/folders/k9/vnpft_6d7qs6xmdb9_4svvmw0000gn/t/foo20141103-1483-gtxc88> [3] pry(main)> file.write('<html><body><script>document.write("hello world");</script></body></html>') => 73 [4] pry(main)> file.rewind => 0 [5] pry(main)> result = phantomjs.run("./app/assets/javascripts/process.js", file.path); [6] pry(main)> result => "<html><head></head><body>function read() {\n [native code]\n}</body></html>"

note unexpected {\n[native code]\n}.

why not importing javascript?

javascript phantomjs

No comments:

Post a Comment