-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added an option for adding key/values to phjs' page.customHeaders #21
Changes from 4 commits
60c9824
501000c
5706576
d516aaf
8bfd4d6
bc3aea0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,14 @@ The best way to understand how this lib should be used is by looking at the [gru | |
|
||
Also, in the case of the grunt-contrib-qunit plugin, it's important to know that the page being loaded into PhantomJS *doesn't* know it will be loaded into PhantomJS, and as such doesn't have any PhantomJS->Grunt code in it. That communication code, aka. the ["bridge"](https://github.com/gruntjs/grunt-contrib-qunit/blob/master/phantomjs/bridge.js), is dynamically [injected into the html page](https://github.com/gruntjs/grunt-contrib-qunit/blob/master/tasks/qunit.js#L136). | ||
|
||
### Options | ||
|
||
This lib has a few options that can be added to it: | ||
|
||
* `timeout`: phantomjs' timeout, in milliseconds. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PhantomJS There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
* `inject`: Javascript to inject into the page. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JavaScript There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
* `page`: an object of options for the phantomjs `page` object. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PhantomJS Also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
|
||
## An inline example | ||
|
||
If a Grunt task looked something like this: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,9 @@ | |
"devDependencies": { | ||
"grunt-contrib-jshint": "~0.1.1", | ||
"grunt": "~0.4.0", | ||
"difflet": "~0.2.3" | ||
"difflet": "~0.2.3", | ||
"express": "~3.1.1", | ||
"underscore": "~1.4.4" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lodash There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
}, | ||
"main": "lib/phantomjs" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,13 @@ var inject = function() { | |
injected = true; | ||
}; | ||
|
||
// Add options to the page. | ||
if (options.page) { | ||
for (var prop in options.page) { | ||
page[prop] = options.page[prop]; | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
// Keep track if the client-side helper script already has been injected. | ||
page.onUrlChanged = function(newUrl) { | ||
injected = false; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<script> | ||
|
||
// Send messages to the parent PhantomJS process via alert! Good times!! | ||
function sendMessage() { | ||
var args = [].slice.call(arguments); | ||
alert(JSON.stringify(args)); | ||
} | ||
|
||
// Template the headers out | ||
var headers = { | ||
<% _.each(_.pairs(headers), function(pair) { %> "<%= pair[0] %>":"<%= pair[1] %>", <% }); %> | ||
}; | ||
|
||
for (var prop in headers) { | ||
sendMessage('debug', prop + ":" + headers[prop]); | ||
} | ||
sendMessage('test', headers['x-custom']); | ||
sendMessage('done'); | ||
|
||
</script> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var _ = require('underscore'); | ||
var fs = require('fs'); | ||
var express = require('express'); | ||
var port = 8000; | ||
var site = express(); | ||
|
||
site.get('*', function(req, res) { | ||
fs.readFile('./test/fixtures/headers.html', 'utf8', function (err, data) { | ||
if (err) throw err; | ||
var h_tmpl = _.template(data); | ||
res.write(h_tmpl({headers: req.headers})); | ||
res.end(); | ||
}); | ||
}); | ||
|
||
site.listen(port); | ||
|
||
console.log("Listening on port " + port); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single quotes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moot sentence
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed