Proxy CLI Option --proxy=address:port Not working for me in CasperJS -> however works fine in PhantomJS

4,967 views
Skip to first unread message

Ryan Sullivan

unread,
Feb 8, 2012, 7:14:39 PM2/8/12
to casp...@googlegroups.com
Hi,

I'm having problems getting the Proxy CLI Option to work when running CasperJS. -> works fine when running just PhantomJS

My command looks like this:

xvfb-run casperjs --proxy=192.168.1.42:8080 casperproxycheck.js

(192.168.1.42:8080 is not my proxy - provided for example purposes)

My script 'casperproxycheck.js' does this:

var casper = require('casper').create();

casper.start('http://whatismyipaddress.com/', function() {
    this.debugPage();
});

casper.run();

The Result is my server's IP and not the proxy IP.


However, w/ PhantomJS, it works!

PhantomJS command:

xvfb-run phantomjs --proxy=192.168.1.42:8080 phantomproxycheck.js

My script 'phantomproxycheck.js' does this:

var page = new WebPage();

page.open('http://whatismyipaddress.com/', function (status) {
    if (status !== 'success') {
        console.log('Unable to access network');
    } else {
        var ua = page.evaluate(function () {
            return document.getElementById('section_content').innerText;
        });
        console.log(ua);
    }
    phantom.exit();
});

The Result is my proxy IP address - it works with just Phantomjs.

I'd be grateful for any help you can give.  I'm hoping that casperjs will be a good fit for my testing/projects.

Thanks,
Ryan

nick c

unread,
Feb 8, 2012, 9:39:26 PM2/8/12
to casp...@googlegroups.com
I had a similar problem, casperjs python script doesn't seem to pass on the proxy arg.. 
To get around this I stopped using the casperjs python script.

To bypass the python loader, just add this to the top of your script..

phantom.casperPath = '/path/to/casper';
phantom.injectJs(phantom.casperPath +'/bin/bootstrap.js');

Now you can use phantomjs binary instead of casperjs python script to run your scripts..

Ryan Sullivan

unread,
Feb 8, 2012, 10:55:06 PM2/8/12
to casp...@googlegroups.com
Hi Nick! 

Thanks for the work around!

Much appreciated.

Ryan

Nicolas Perriault

unread,
Feb 9, 2012, 2:52:43 AM2/9/12
to casp...@googlegroups.com
2012/2/9 Ryan Sullivan <sul...@gmail.com>:

> Thanks for the work around!
>
> Much appreciated.

I've just pushed an attempt to fix the issue with the casperjs
executable, could you please test latest master and provide some
feedback?

If it actually solves the issue I'll be releasing 0.6.4 today.

Thanks

--
Nicolas Perriault
http://www.akei.com/http://prendreuncafe.com/
Mobile: +33 660 92 08 67 — Skype: nperriault

Ryan Sullivan

unread,
Feb 9, 2012, 2:22:55 PM2/9/12
to casp...@googlegroups.com
That works!  Thanks Nicolas!  You guys are really helpful :)

Andrea Bisello

unread,
Dec 27, 2012, 3:04:17 PM12/27/12
to casp...@googlegroups.com
hi

i installed tor proxy (www.torproject.org ) ;

i'm using the last version of phantomjs and casperjs

i'm connected to tor network by a proxy 127.0.0.1:9050 ( i see it with netstats )

if i use the Ryan Sullivan's test page (thanks Ryan) i obtain my ip (79.x.x.x.) and not my tor ip (108....). (Screenshot attached)



can you help me?

thanks




real-ip.JPG

Nicolas Perriault

unread,
Dec 27, 2012, 3:50:28 PM12/27/12
to casp...@googlegroups.com
On Thu, Dec 27, 2012 at 9:04 PM, Andrea Bisello
<andrea....@gmail.com> wrote:

> if i use the Ryan Sullivan's test page (thanks Ryan) i obtain my ip
> (79.x.x.x.) and not my tor ip (108....). (Screenshot attached)
>
> can you help me?

Many possible causes but I suspect this PR being related
https://github.com/n1k0/casperjs/pull/270

Can you please try to patch this commit back and tell me if it solves
the issue? https://github.com/n1k0/casperjs/commit/0d659f140f1e2120bed967d8301657b5fe79f19c

++

--
Nicolas Perriault
https://nicolas.perriault.net/
Phone: +33 (0) 660 92 08 67

Andrea Bisello

unread,
Dec 28, 2012, 5:35:30 PM12/28/12
to casp...@googlegroups.com, nic...@perriault.net
Hi

i tried to restore the code ( i use tortoise svn, not gib )

obtaining this bat

@ECHO OFF
set CASPER_PATH=%~dp0..
set CASPER_BIN=%CASPER_PATH%\bin\
set PHANTOMJS_NATIVE_ARGS=(--cookies-file --config --debug --disk-cache --ignore-ssl-errors --load-images --load-plugins --local-storage-path --local-storage-quota --local-to-remote-url-access --max-disk-cache-size --output-encoding --proxy --proxy-auth --proxy-type --remote-debugger-port --remote-debugger-autorun --script-encoding --web-security)

set PHANTOM_ARGS=
set CASPER_ARGS=

:Loop
if "%1"=="" goto Continue
set IS_PHANTOM_ARG=0

for %%i in %PHANTOMJS_NATIVE_ARGS% do (
if "%%i"=="%1" set IS_PHANTOM_ARG=1
)
if %IS_PHANTOM_ARG%==0 set CASPER_ARGS=%CASPER_ARGS% %1

if %IS_PHANTOM_ARG%==1 set PHANTOM_ARGS=%PHANTOM_ARGS% %1

shift
goto Loop
:Continue


call phantomjs%PHANTOM_ARGS% %CASPER_BIN%bootstrap.js --casper-path=%CASPER_PATH% --cli%CASPER_ARGS%


but when i call casperjs i obtain

C:\casperjs\batchbin>call phantomjs --proxy C:\casperjs\batchbin\..\bin\bootstrap.js --casper-path=C:\casperjs\batchbin\.. --cli 127.0.0.1:9050 prox.js
Error: Unknown option: casper-path


maybe i do something wrong ... 

Nicolas Perriault

unread,
Dec 29, 2012, 2:24:25 AM12/29/12
to casp...@googlegroups.com
On Fri, Dec 28, 2012 at 11:35 PM, Andrea Bisello
<andrea....@gmail.com> wrote:

> i tried to restore the code ( i use tortoise svn, not gib )
>
> maybe i do something wrong ...

The previous version of the file is here
https://github.com/langholz/casperjs/blob/c00068c7d51342baeeb7b35968b363bda88a7daa/batchbin/casperjs.bat
Message has been deleted

Anil Kumar Pandey

unread,
Feb 22, 2014, 2:44:01 AM2/22/14
to casp...@googlegroups.com
Hello Sir, 
                    The Solution is not working for me.. I am using W8 and ran my script but its not showing proxy IP.

=========command============
c:\> casperjs --proxy=192.168.1.42:8080 casperproxycheck.js

(I wrote the same IP address which I mentioned above in command, Please let me know if am I doing something wrong.)

=========casperjs code========
phantom.casperPath = "F:\\User\\javascript\\casperjs-1.1-beta1";
phantom.injectJs(phantom.casperPath +'\\bin\\bootstrap.js');
console.log(phantom.casperPath);
var selector = "div.the-ip";
var casper = require('casper').create();
casper.start(url, function() {
  this.waitForSelector(selector, function then() {
    this.evaluate(function(sel) {
      document.querySelector(sel).style.backgroundColor = "black";
    }, selector);
    this.captureSelector("ip.png", selector);
  }, function onTimeout() {
    this.die("URL timed out.");
  });
});

casper.run();
Reply all
Reply to author
Forward
0 new messages