Managing Google Chrome through a Perl script

I was looking for a way to check for changes to a specific URL provided by the user. I wrote a script that I ran at home that can do this successfully using WWW::Mechanize . The thing is, I need to run it on another computer network with a group policy that blocks all requests $mech->get($url) (these are not problems with the firewall, I assume Perl), so I decided to try and solve this problem letting Perl control the web browser.

The computers on the network only work with Google Chrome and IE8, and I can’t install Firefox due to a different policy (I thought about using WWW::Mechanize::Firefox ). I don't want to call IE8 in a script because most of the URLs that will be provided will have websites that do not work with it, so that only leaves me with Chrome.

Searching for a module that can do this, I found AnyEvent::Chromi :

which provides all the Chrome extension APIs through a connection to a web server.

This does not work (the policy probably also blocks this websocket).

Is there any other way around this problem / manage Chrome from Perl script?

+7
google-chrome perl
source share
2 answers

Since you mentioned IE8, I assume that you are dealing with a Windows system. And since you mentioned that you considered WWW: Mechanix :: Firefox, it looks like you are not limited to just the main modules.

Based on this, the only way I can think of to automate the Chrome browser is to use Win32 :: GuiTest to control the Chrome browser. If you can figure out how to manually control testing using only keyboard input (i.e., Without a mouse), this will make the task easier than trying to calculate the mouse emulation to get the cursor in the correct position for various tasks.

I'm not sure if this is a route you want to use or not. This is the only way I can come up with what you want to do with the constraints you have to deal with.

+1
source share

You can also do this from scratch without using CPAN modules. I tested this on Linux (Ubuntu 16.04, Google Chrome version 53) using Unix Domain (UD) Sockets. Unfortunately, it seems that Windows does not have UD sockets, but this should be possible to do from Windows using named pipes.

First make sure google-chrome running in the background. We will need to create a Chrome application that will communicate with its own host through the built-in messaging API . native host can be any script that reads messages from STDIN and returns responses via STDOUT . I tested both Python script and Perl script.

Now, so that the stand-alone Perl script can communicate with the Chrome Browser, it will send the request through the UD socket (created by the native host) to its own host; the internal host will then forward the request to google-chrome through its standard output pipe. Then the Chrome application (written in JavaScript) will receive the request. The Chrome application will use the Chrome JavaScript API to retrieve the requested data and return it to the host. Finally, the native host redirects the result through the Perl script socket.

As you can see, there are some details needed to configure this, but I can confirm that it works on my Linux platform. Please let me know if you need more details.

+1
source share

All Articles