Documenting Problems That Were Difficult To Find The Answer To

How Do I Get The Current Page URL In PhantomJS?

If you simply do the following in PhantomJS:

console.log( "- current url is " + document.URL );

then you will see the javascript filename you are running with PhantomJS.

If you want to see the URL of the currently loaded page, however, then you have to do it within the loaded page’s sandbox:

var url = page.evaluate(
    function () {
        return document.URL;

console.log( "- current url is " + url );

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: