Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added ability to set User-Agent on the browser via Browser#userAgent

  • Loading branch information...
commit 3f1db496984c4bcdc2ef74c2ad0dcd01e5db4310 1 parent 300f9a2
@bnoguchi bnoguchi authored
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/browser.js
View
16 lib/browser.js
@@ -119,16 +119,21 @@ Browser.prototype.context = function(selector, fn){
Browser.prototype.hostBrowser = function(uri) {
var otherHostname = uri.hostname
, port = uri.port || (uri.protocol === 'https:' ? 443 : 80)
- , browsers = Browser.browsers;
+ , browsers = Browser.browsers
+ , otherBrowser;
if (!browsers) {
browsers = Browser.browsers = {};
}
if (!browsers[this.host]) {
browsers[this.host] = this;
}
- return browsers[otherHostname] ||
- (browsers[otherHostname] = new Browser(port, otherHostname));
- return otherBrowser.request(method, path, options, fn, saveHistory);
+ otherBrowser = browsers[otherHostname];
+ if (!otherBrowser) {
+ otherBrowser =
+ browsers[otherHostname] = new Browser(port, otherHostname);
+ otherBrowser.userAgent = this.userAgent;
+ }
+ return otherBrowser;
};
/**
@@ -185,6 +190,9 @@ Browser.prototype.request = function(method, path, options, fn, saveHistory){
var cookies = this.cookieJar.cookieString({ url: path });
if (cookies) headers.Cookie = cookies;
+ // User-Agent
+ if (this.userAgent) headers['User-Agent'] = this.userAgent;
+
// Request body
if (options.body) {
headers['Content-Length'] = options.body.length;
Please sign in to comment.
Something went wrong with that request. Please try again.