Headless Chrome Javascript API/headless_shell questions

691 views
Skip to first unread message

Deepak Kumar

unread,
Sep 7, 2016, 6:49:46 PM9/7/16
to headless-dev
Hi! 

I successfully built the headless_shell application, and it works like a charm. I'm brand new to headless browsing in general, but had a few questions based on my experiences w/ PhantomJS and some things I've been trying with headless_shell.

1. Is there a list of headless_shell command line inputs documented somewhere? I looked around at different pieces of documentation and have found some things (for example, --dump-dom and --screenshot), but can't seem to find any information about general headless_shell usage.

2. In using PhantomJS, there is a very easy plug and play Javascript API which utilizes the underlying library 

For example (from their homepage):

page = require('webpage').create()
page
.open("https://www.google.com", function(status){
   
//do something
    phantom
.exit()
})

Is there something similar for headless chrome yet? And if so, is there documentation on how it all works?

Thanks for your time.

Salvador Faria

unread,
Sep 7, 2016, 6:51:54 PM9/7/16
to headless-dev
Did a build of headless_shell today hehe.
Looking to see if there is any way i could use headless_shell to save HAR files.

Paul Irish

unread,
Sep 7, 2016, 10:13:39 PM9/7/16
to Salvador Faria, headless-dev
The primary api of headless is via the chrome debugging protocol.

cyrus-and/chrome-remote-interface provides a nice nodejs based API to start working with the protocol, and in fact... The same author created cyrus-and/chrome-har-capturer which will capture network activity and generate a HAR from it. :)

Here's a basic load-a-page-and-take-a-screenshot example: headless-snap/index.js

Also, I would recommend reading these two guides as background:

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev+unsubscribe@chromium.org.
To post to this group, send email to headle...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/headless-dev/a7e7270d-f5c3-4351-b300-0a51d5a43841%40chromium.org.

Deepak Kumar

unread,
Sep 8, 2016, 12:04:21 AM9/8/16
to headless-dev, salv...@bynd.com
Appreciate it! 
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.

To post to this group, send email to headle...@chromium.org.

Sami Kyostila

unread,
Sep 8, 2016, 11:19:21 AM9/8/16
to Deepak Kumar, headless-dev, salv...@bynd.com
Thanks Paul! One more tip: see headless_shell_switches.cc for the supported command line options.

- Sami

Deepak Kumar

unread,
Sep 8, 2016, 3:37:37 PM9/8/16
to headless-dev, salv...@bynd.com
Hi Paul,

Thanks a lot. Do you know if headless currently supports modification of the user-agent string? There is an API call in Chrome Debugging Protocol (Network.setUserAgentOverride()) but it doesn't seem to have an effect.

Cheers,
Deepak

On Wednesday, September 7, 2016 at 9:13:39 PM UTC-5, Paul Irish wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.

To post to this group, send email to headle...@chromium.org.

Paul Irish

unread,
Sep 8, 2016, 3:50:05 PM9/8/16
to Deepak Kumar, salv...@bynd.com, headless-dev
Yes. Use that method but call Network.enable first. :)

To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev+unsubscribe@chromium.org.

To post to this group, send email to headle...@chromium.org.

Deepak Kumar

unread,
Sep 8, 2016, 4:32:40 PM9/8/16
to headless-dev, deb...@gmail.com, salv...@bynd.com
Hey Paul,

Thanks again for all your help. I'm using the example Javascript that takes a screenshot as a model for this user-agent modification, which I'm linking here: https://jsfiddle.net/qx7o4gue/

If you have the time for a quick spot check, is there something immediate that you can see where I'm going wrong? I'm calling the function after Network.enable().

Thanks a ton.
Deepak

Deepak Kumar

unread,
Sep 8, 2016, 4:47:56 PM9/8/16
to headless-dev, deb...@gmail.com, salv...@bynd.com
Nevermind, apparently I don't know anything about Javascript. Thanks again!
Reply all
Reply to author
Forward
0 new messages