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

Add support for headless Chrome/ChromeCanary #111

Merged
merged 2 commits into from
May 1, 2017

Conversation

dpogue
Copy link
Contributor

@dpogue dpogue commented Mar 21, 2017

Tested on Linux with google-chrome-unstable, but as of today it should be support in macOS Chrome Canary as well.

Not really expecting this to be merged until headless support hits a stable release across multiple OSes, but figured I'd open a PR for anyone trying to figure out how to get it working. I was thinking of publishing it to npm as karma-headless-chrome-launcher, but it seems that name is already in use.

@dignifiedquire
Copy link
Member

Thank you, I'm generally not opposed to merge this, but I would like some docs saying that it is experimental and where to look for details about it.

@dignifiedquire
Copy link
Member

It would also be great if we could add it to travis and test it there if that's possible

expect(headlessGetOptions.call(context, url, args, parent)).to.be.eql([
'-incognito',
'--headless',
'--disable-gpu',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curiosity: What are the pros of using incognito and disable-gpu?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--disable-gpu is currently needed with headless because of linking errors with osmesa.so. That will hopefully not be required once Chrome switches to their SwiftShader library as a software rendering engine. See https://bugs.chromium.org/p/chromium/issues/detail?id=617551 for details.

-incognito is just an example flag in the test, ensuring that it gets passed through.

@agaripian
Copy link

@dpogue thanks for this PR! I am using your repo/branch for karma-chrome-launcher but I am getting the following Error inside my docker container. Any Ideas what might be causing the
EACCES error? Its using ubuntu:16.04 I also started the container with --cap-add=SYS_ADMIN

18 04 2017 03:49:43.520:INFO [launcher]: Starting browser ChromeCanaryHeadless
18 04 2017 03:49:43.538:ERROR [karma]: { Error: spawn EACCES
    at exports._errnoException (util.js:1018:11)
    at ChildProcess.spawn (internal/child_process.js:319:11)
    at exports.spawn (child_process.js:378:9)
    at spawnWithoutOutput (/app/node_modules/karma/lib/launchers/process.js:145:24)
    at Object.ProcessLauncher._execCommand (/app/node_modules/karma/lib/launchers/process.js:63:21)
    at Object.ProcessLauncher._start (/app/node_modules/karma/lib/launchers/process.js:28:10)
    at Object.<anonymous> (/app/node_modules/karma/lib/launchers/process.js:14:10)
    at emitOne (events.js:101:20)
    at Object.emit (events.js:188:7)
    at Object.BaseLauncher.start (/app/node_modules/karma/lib/launchers/base.js:42:10)
    at Object.j (/app/node_modules/karma/lib/launcher.js:116:17)
    at Object.setTimeout.bind.j (/app/node_modules/qjobs/qjobs.js:143:18)
    at ontimeout (timers.js:380:14)
    at tryOnTimeout (timers.js:244:5)
    at Timer.listOnTimeout (timers.js:214:5)
 code: 'EACCES', errno: 'EACCES', syscall: 'spawn' }

npm ERR! Linux 4.4.17-boot2docker
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "karma"
npm ERR! node v6.10.2
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! be.net@0.0.0 karma: `karma start --single-run --verbose`
npm ERR! Exit status 1

@dpogue
Copy link
Contributor Author

dpogue commented Apr 18, 2017

That sort of error seems to be common if you ran the npm install with sudo and are trying to run the karma command without sudo. Maybe try a chown/chmod on your node_modules folder?

@agaripian
Copy link

I figured it out.. It was related to my env variable that I had set, Once I removed it it worked fine. process.env.CHROME_CANARY_BIN = '/opt/google/chrome-unstable'; <- that caused the issue.

@unseen1980
Copy link

I can confirm that in my case it worked without issues. I used it for unit testing. Great work, thanks @dpogue 👍

name: 'ChromeHeadless',

DEFAULT_CMD: {
// Try chromium-browser before chromium to avoid conflict with the legacy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is out of date, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, yes it is (although it is also out-of-date further up in the file where I copied this block from)

@klaussilveira
Copy link

My simpler Jenkins setup likes this. 👍

@dpogue
Copy link
Contributor Author

dpogue commented May 1, 2017

For those who are wanting to use this before it's merged, you can tell npm to install it from the git branch:
npm install --save-dev dpogue/karma-headless-chrome-launcher

Headless Chrome is supported in Chrome 59 on Linux and Mac. Windows is not supported yet (they're aiming for Chrome 60). See https://developers.google.com/web/updates/2017/04/headless-chrome for more info about headless chrome.

I have added tests to the PR, and will try to get some docs written.

@rogeriopvl
Copy link
Collaborator

@dignifiedquire I think we're good to merge this. Do you agree?

@dignifiedquire dignifiedquire merged commit 7446181 into karma-runner:master May 1, 2017
@dignifiedquire
Copy link
Member

Thank you everyone 🎉

@egoroof
Copy link

egoroof commented May 2, 2017

Will it be a new release soon?

@dignifiedquire
Copy link
Member

@rogeriopvl I can cut a new release, but maybe this should be fixed first #120?

@rogeriopvl
Copy link
Collaborator

@dignifiedquire #120 doesn't sound at all related with karma-chrome-launcher.

@mgol
Copy link
Contributor

mgol commented May 2, 2017

@dignifiedquire #120 is not a bug, it will fail like that for people trying this with current stable Chrome, i.e. v58 (and maybe even with v59 on Windows as there it will be officially supported only in v60 & newer).

@dignifiedquire
Copy link
Member

Okay will do a release then

@dignifiedquire
Copy link
Member

done 2.1.0

@cmacdonnacha
Copy link

cmacdonnacha commented Dec 8, 2017

Will this work with Bamboo CI? I changed my karma config from:

browsers: ['PhantomJS']

to

browsers: ['ChromeHeadless']

but it seems to be failing now.

Also, does this default to phantomjs if chrome headless fails?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants