Skip to content

Commit

Permalink
Add support for second url argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala committed Nov 2, 2012
1 parent 061a8aa commit cce2ad5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions Readme.md
Expand Up @@ -13,10 +13,18 @@ let you run node module in a headless browser environment.


## Usage ## Usage


phantomify ./path/to/index.js phantomify ./path/to/module.js


[Phantomify][] will make a browserify bundle for the given module path [Phantomify][] will make a browserify bundle for the given module path
and then will load & execute it in an empty HTML page in a [PhantomJS][]. and then will load & execute it in an empty "about:blank" page in a
[PhantomJS][].


Sometimes "about:blank" is just not good enough there for [Phantomify][]
can be given second argument for the page URL where code should be executed:

phantomify ./path/to/module.js http://localhost:8080/



## Install ## Install


Expand Down
3 changes: 1 addition & 2 deletions phantom-bootstrap.js
Expand Up @@ -24,8 +24,7 @@ page.onClosing = function(closingPage) {
var code = closingPage.url.split("#")[1] var code = closingPage.url.split("#")[1]
phantom.exit(code && parseInt(code)) phantom.exit(code && parseInt(code))
} }
page.open("about:blank", function onPage(status) { page.open(system.args[2] || "about:blank", function onPage(status) {
console.log(system.args[1])
var source = fs.read(system.args[1]) var source = fs.read(system.args[1])
page.evaluateAsync(Function(source)) page.evaluateAsync(Function(source))
}) })
3 changes: 2 additions & 1 deletion phantomify.js
Expand Up @@ -149,7 +149,8 @@ function phantomify(main) {


if (bundle.ok) { if (bundle.ok) {
fs.writeFileSync(file, source) fs.writeFileSync(file, source)
var phantomjs = spawn("phantomjs", [ bootstrap, file ], { var args = [ bootstrap, file ].concat(process.argv.slice(3))
var phantomjs = spawn("phantomjs", args, {
stdio: "inherit" stdio: "inherit"
}) })
phantomjs.once("exit", function(code) { phantomjs.once("exit", function(code) {
Expand Down

0 comments on commit cce2ad5

Please sign in to comment.