3

Can CasperJS (with phantomJS) be run directly in the browser and not via the command line ?

I would like to run an interactive test from the browser where i take inputs from the user and proceed accordingly. I would like to run casperJS as a normal javascript function which is executed in a browser and be able to produce the output of each command to the user, such that the user can decide what he wants to do next.

4

1 回答 1

4

The short answer is: No, not as you've described it. CasperJS runs on, and depends on, PhantomJS, which is a browser - it can't run in a user's browser.

If you want to offer an interactive CasperJS session through a webpage, you'd need to run Casper/Phantom on a server, and then proxy the input/ouput through that server. Basically any operation that requires fetching other webpages and scraping or interacting with them is likely to require a server-side mechanism, because the Same Origin Policy makes this quite difficult to implement using client-side JavaScript (though a browser extension might be able to do it).

于 2013-08-15T16:42:29.570 回答