Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Lightweight automation of Chrome?

159 views
Skip to first unread message

Matthew Hiles

unread,
Jul 24, 2018, 4:48:13 PM7/24/18
to
I know can I go the full-blown selenium route, but is there a lighter-weight way of controlling a headless chrome instance (in TCL, obviously)?

I've had mixed success trying to [open "|chrome --headless"] -- I'm missing the ability to wait for a page to finish loading.

Basically I want to interface with a website like perl's WWW::Mechanize, but need a real browser to do it. I tried doing it in straight Tcl as well as WWW::Mechanize, but both of these seem to be missing something that the server on the other end is expecting.

stefan

unread,
Jul 25, 2018, 3:31:48 AM7/25/18
to
> I've had mixed success trying to [open "|chrome --headless"] -- I'm missing the ability to wait for a page to finish loading.

What is your expectation exactly? Just by starting chrome in --headless mode, there is no instrumentation triggered unless you use the predefined CLI flags (PDF printing, making screenshots etc.) page loading?

IIRC, one would have to start one chrome instance in debugging mode (w/ or w/o --headless) listening on a given or chosen TCP port (as the DevTools protocol server):

--remote-debugging-port=9222 O

One then has to write a (minimal) DevTools protocol client communicating via ws + JSON with the server.

Alternatively, have a look at: https://sourceforge.net/projects/selenium-tcl/

Cheers, Stefan

Matthew Hiles

unread,
Jul 25, 2018, 8:54:10 AM7/25/18
to
Ah, I missed a key part of the command line: --repl

So I can write javascript to the process and read back the results.

> Alternatively, have a look at: https://sourceforge.net/projects/selenium-tcl/

Also, I was surprised to see my name on that page. Apparently, I helped fix a bug in selenium-tcl a couple years ago. I think I'm stuck in a multi-year loop.

maw...@gmail.com

unread,
Aug 6, 2018, 1:32:44 PM8/6/18
to
Hi,
Regarding WWW::Mechanie - you can try WWW::Mechanize::Chrome (https://metacpan.org/pod/WWW::Mechanize::Chrome) is uses real Chrome.

Regards,
Mariusz

Matthew Hiles

unread,
Aug 6, 2018, 1:51:28 PM8/6/18
to
Excellent, thank you. I hadn't realized that existed.

I actually figured out the problem--why WWW::Mechanize and my own Tcl code wasn't working--turns out the server I was talking to loses your session info if you drop the connection. Adding the -keepalive 1 option makes it work flawlessly. So my very lightweight, pure Tcl code works.
0 new messages