Skip to content
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

Allow passing --headless=new #274

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions index.js
Expand Up @@ -168,7 +168,6 @@ ChromeBrowser.$inject = ['baseBrowserDecorator', 'args']

function headlessGetOptions (url, args, parent) {
var mergedArgs = parent.call(this, url, args).concat([
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage'
])
Expand All @@ -177,9 +176,17 @@ function headlessGetOptions (url, args, parent) {
return flag.indexOf('--remote-debugging-port=') !== -1
}

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

var isHeadlessFlag = function (flag) {
return flag.indexOf('--headless=') !== -1
}

return mergedArgs.some(isHeadlessFlag)
? mergedArgs
: mergedArgs.concat(['--headless'])
}

var ChromeHeadlessBrowser = function (baseBrowserDecorator, args) {
Expand Down
24 changes: 20 additions & 4 deletions test/jsflags.spec.js
Expand Up @@ -64,10 +64,10 @@ describe('headlessGetOptions', function () {
var args = {}
expect(headlessGetOptions.call(context, url, args, parent)).to.be.eql([
'-incognito',
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage',
'--remote-debugging-port=9222'
'--remote-debugging-port=9222',
'--headless'
])
})

Expand All @@ -81,9 +81,25 @@ describe('headlessGetOptions', function () {
expect(headlessGetOptions.call(context, url, args, parent)).to.be.eql([
'-incognito',
'--remote-debugging-port=9333',
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage'
'--disable-dev-shm-usage',
'--headless'
])
})

it('should not overwrite custom headless flag', function () {
var parent = sinon.stub().returns(
['-incognito', '--headless=new']
)
var context = {}
var url = 'http://localhost:9876'
var args = {}
expect(headlessGetOptions.call(context, url, args, parent)).to.be.eql([
'-incognito',
'--headless=new',
'--disable-gpu',
'--disable-dev-shm-usage',
'--remote-debugging-port=9222'
])
})
})