1

I have the following code, when I run it like so

phantomjs test-script.js http://phantomjs.org 

I get an erorr of "SyntaxError: Parse Error". I'm newish to javascript and without a line number with the error I am lost. Here is the code

var args = require('system').args;
var url = "";

args.forEach(function(arg, i) {
        url = arg;
});


var page = require('webpage').create();

var pageLoaded = function({

page.open(url, function (status) {
    if (status !== 'success') {
        console.log('Unable to access network');
    } else {
        page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js", function() {
            var data = page.evaluate(function() {
                return $("body").html();
            });

            var title = page.evaluate(function () {
                return document.title;
            });

            console.log('<title>' + title + '</title>');
            console.log(data);
            page.close();
            phantom.exit();
        });
    }
   });
});    

var try_to = function() {
  setTimeout(pageLoaded, 1000);
};

try_to();

I looked at PhantomJS sometimes gives "parse error" messages and getting more information from phantomjs "SyntaxError: Parse error" message Neither give me more information to debug. I've checked multiple sites and am not getting the gzip issue mentioned in that first link. I think it's something w/ the code. As if I remove the try_to() function, all things work.

Community
  • 1
  • 1
user985590
  • 41
  • 1
  • 2
  • 6
  • possible duplicate of [getting more information from phantomjs "SyntaxError: Parse error" message](http://stackoverflow.com/questions/14905664/getting-more-information-from-phantomjs-syntaxerror-parse-error-message) – gcb Oct 25 '13 at 21:55

2 Answers2

2

Copy and paste that js into jslint, I just tried it and found many errors, some trivial, but some major. You are missing a ) on your pageloaded function for starters.

sebagomez
  • 9,501
  • 7
  • 51
  • 89
box86rowh
  • 3,415
  • 2
  • 26
  • 37
0

Use an online JavaScript validator such as http://esprima.org/demo/validate.html.

Ariya Hidayat
  • 12,523
  • 3
  • 46
  • 39