Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CasperJS: Disable remote page's javascript but still use casper.evaluate?

Thanks for reading my topic, I'd be really grateful if anyone could suggest any other avenues I should explore to achieve the below.

Using CasperJS or PhantomJS I need to disable all JavaScript that belongs to the pages I navigate from being executed, while still being able to run my own using casper.execute.

Does anyone know a way I can do this?

  • Is it possible to modify the HTTP headers or bodies using onResourceRequested or onResourceReceived? or cancel a request conditionally? or are they read only?
  • Can you modify the raw HTML source before it's offered for parsing?
  • I've tried hacking a window.stop() in a casper.execute early, but this works inconsistently between pages.
  • Is the Phantom WebServer module used for this kind of thing? Could/Should I route reqs/responses through that and modify them as they pass through?

Thanks for any help - I appreciate this is a weird use case.

like image 792
Jamie Mason Avatar asked Oct 25 '12 10:10

Jamie Mason


1 Answers

As stated here it is possible but not with the current phantomjs master branch but in a specific [dev branch[(https://github.com/Vitallium/phantomjs/tree/allow-to-disable-js), you should build from, look for the latest commit for disable-javascript option.

like image 191
alonisser Avatar answered Oct 13 '22 23:10

alonisser