Skip to content

Commit

Permalink
fix: allow overriding of default debug port
Browse files Browse the repository at this point in the history
This allows the --remote-debugging-port flag to be overridden with a
custom port when using chrome headless.

Fixes #187
  • Loading branch information
rogeriopvl committed Nov 19, 2018
1 parent 01c7efc commit 1284e5b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,15 @@ ChromeBrowser.prototype = {
ChromeBrowser.$inject = ['baseBrowserDecorator', 'args']

function headlessGetOptions (url, args, parent) {
return parent.call(this, url, args).concat(['--headless', '--disable-gpu', '--remote-debugging-port=9222'])
var mergedArgs = parent.call(this, url, args).concat(['--headless', '--disable-gpu'])

var isRemoteDebuggingFlag = function (flag) {
return flag.indexOf('--remote-debugging-port=') !== -1
}

return mergedArgs.some(isRemoteDebuggingFlag)
? mergedArgs
: mergedArgs.concat(['--remote-debugging-port=9222'])
}

var ChromeHeadlessBrowser = function (baseBrowserDecorator, args) {
Expand Down
15 changes: 15 additions & 0 deletions test/jsflags.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,19 @@ describe('headlessGetOptions', function () {
'--remote-debugging-port=9222'
])
})

it('should not overwrite custom remote-debugging-port', function () {
var parent = sinon.stub().returns(
['-incognito', '--remote-debugging-port=9333']
)
var context = {}
var url = 'http://localhost:9876'
var args = {}
expect(headlessGetOptions.call(context, url, args, parent)).to.have.members([
'-incognito',
'--headless',
'--disable-gpu',
'--remote-debugging-port=9333'
])
})
})

0 comments on commit 1284e5b

Please sign in to comment.