Skip to content

Commit

Permalink
feat: allow overriding of the 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 authored and dignifiedquire committed Nov 20, 2018
1 parent 2042822 commit 26ae9f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
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
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.be.eql([
'-incognito',
'--remote-debugging-port=9333',
'--headless',
'--disable-gpu'
])
})
})

0 comments on commit 26ae9f4

Please sign in to comment.