Controlling Google Chrome via Perl script - perl

I was looking for a way to check for changes in a specific URL provided by the user. I wrote a script that I ran at home that can do that successfully using WWW::Mechanize. The thing is, I need to run it in another computer network that has a group policy that blocks all $mech->get($url) requests (it's not firewall problems, I let Perl through), so I thought I'll try and work around this problem by letting Perl control the web browser.
The computers in the network run Google Chrome and IE8 only and I can't install Firefox due to another policy (thought of using WWW::Mechanize::Firefox). I don't want to invoke IE8 in the script because most of the URLs that will be provided will be of websites that don't work well with it, so that leaves me with Chrome only.
Searching for a module that can do that, I only found AnyEvent::Chromi:
which exposes all of the Chrome Extensions API via a websocket connection.
This doesn't work (the policy probably blocks that websocket as well).
Is there another way to work around this problem/control Chrome from within a Perl script?

Is there another way to work around this problem/control Chrome from
within a Perl script?
WWW::Mechanize::Chrome
Like WWW::Mechanize, this module automates web browsing with a Perl object. Fetching and rendering of web pages is delegated to the Chrome (or Chromium) browser by starting an instance of the browser and controlling it with Chrome DevTools.

You can also do this from scratch without using any CPAN modules.
I tested this on Linux (Ubuntu 16.04, Google Chrome version 53) using Unix Domain (UD)
sockets. Unfortunately, it seems Windows does not have UD sockets, but
it should be possible to do same from Windows using named pipes.
First, make sure google-chrome is running in the background. We will
need to create a Chrome App
that will communicate
with a native host through the native messaging
API. The
native host can be any script that reads messages from its STDIN and
returns replies through its STDOUT. I tested both a Python
script and a Perl script.
Now, in order for a standalone Perl script to communicate with the
Chrome browser, it will send request through a UD socket (created by
the native host) to the native host; the native host will then
forward the request to google-chrome through its standard output
pipe. Then the Chrome App (written in JavaScript)
will receive the request. The Chrome App will use the Chrome
JavaScript APIs to get the requested data and return it to the native
host. Finally, the native host forwards the result through the socket to
the Perl script.
As you can see, there are some details required for setting this up, but I can
confirm that it works on my Linux platform. Please let me know if you need more
details.

Since you mentioned IE8, I'm assuming that you're dealing with a Windows system. And since you mentioned that you had considered WWW:Mechanix::Firefox, it sounds like you are not being restricted to just core modules.
Based on that, the only way that I can think of to automate the Chrome broswer would be to use Win32::GuiTest to control the Chrome browser. If you can figure out how to manually drive your testing using only keyboard input (i.e. no mouse), that would make things easier than trying to figure out the mouse emulation to get the cursor to the correct position for various tasks.
I'm not sure if that's necessarily a route that you will like to use or not. It's just the only way that I can think of to accomplish what you want to do with the restrictions that you have to deal with.

Related

Native messaging or http

I want to be able to execute local shell commands in a web application.
Chrome Native messaging api seems to be good for that, but as it needs also a service in background, I do not see a real difference with a little http server.
Is there a real structural difference between them? As I see there is somewhere a socket used as an interface.
Is there any other solutions for that?
Chrome Native messaging does not work by calling a running daemon. Instead, it spawns a new process each time sendMessage or connect is called.
While you can keep the process you opened with connect running, if you want to do one-shot commands the sendMessage approach is good.
Do note that you will still need a Chrome App or Extension installed to be able to do it, as well as a (separately installed) Native Host module.

Powershell/Commandline in Modern UI

Is there (or is possible) a standard Powershell or commandline in Modern UI in Win 8.x?
It would be pretty nice to have this app "docked" on a part of screen only (for SSH, etc...) and other desktop apps still could be in fullscreen.
You couldn't do this directly. The PowerShell engine isn't available on WinRT. You might be able to do something like create a WinRT app that uses sockets to communicate to a service on the localhost that executes PowerShell for you and returns the results. That would require you to build that service and install it on machines. If this is for a Windows RT device that won't work because only Microsoft can install desktop apps.

How to run windows command in client side(accessing client machine using browser)?

I found many questions about same issue in Stackoverflow. But could not find any satisfactory answers.
My problem is:
I have to run "iperf client" in client machine(assuming windows) using command line in client windows machine and get the statistics.
Currently my server is written in PHP(I am ready to shift to any platform) given that I shall be able to run iperf command on client machine.
I searched and found that, Java applet, ActiveX control or Plugins(like Google Talk plugin). Can someone suggest me the best and easiest approach here(with some reference links if possible).
You cannot run an arbitrary command on the client side using Native Client. What you can do is invoke Pepper API functions from your extension. Another thing you can do is access the Chrome extension API from Javascript. If none of these have the information you need, feel free to suggest new features on the native-client-discuss mailing list. Note that invoking "any Windows command" cannot be reasonably made part of a client-side application, due to security issues.

Deliver application's GUI via browser

I need to show to a user an interface of some application running on a server using a browser. It should be like RDP-client for a single application on a server.
Are there any solutions or services that can implement following functionality? Maybe Citrix?
Thanks in advance!
This looks like what you're looking for:
http://freerdp.net/
About FreeRDP-WebConnect
FreeRDP-WebConnect is an open source gateway for accessing RDP
sessions using any HTML5 compliant browser. In particular it relies on
the Canvas and the WebSockets feature. FreeRDP-WebConnect is a
subproject of the FreeRDP project.
On the server side, a standalone daemon - written in C++ - provides a
Web page via HTTPS (or HTTP, if configured) and uses FreeRDP libs to
connect as a client to any RDP session. The server side WebSockets
implementation handles current RFC6455 only, so browsers that
implement the older drafts do not work. With RFC6455 being raised to
the "Proposed Standard" level, this should change now really soon.
I would create an account on the server for the user, and only give it access to the one application it needs access to.
You can use Cameyo. To start, create yourself a free account, and click on "Add App". If your installer supports unattended installation, you simply need to submit it. Otherwise, you can build a Cameyo package locally and send it in. It will then be playable as HTML5.
You don't indicate what server you are running on.
As an alternative to FreeRDP-Webconnect cited above, also open source and also using FreeRDP as rdp client through an HTTP gateway, there is Myrtille.
FreeRDP-WebConnect embeds a standalone daemon written in C++ to provide a web page via HTTP(S), and so will also work on Linux servers, while Myrtille have a IIS/.NET (C#) implementation and an MSI installer, thus is more intended for Windows Servers.

Will it be possible to create a Chrome extension that uses a PPAPI plugin without a web server?

In the tutorial Google provided, they mentioned that you had to use a web server. I want my application to run without an Internet connection. Is this possible?
Yes. You have to set up a web server on your machine though. There are free ones on the Internet:
http://www.google.com/search?rlz=1C1CHKZ_enUS437US437&sourceid=chrome&ie=UTF-8&q=free+web+server&qscrl=1
See this SO question:
stumped on jquery call inside chrome extension
...and here is more information from Google:
http://code.google.com/chrome/extensions/experimental.proxy.html
...and some problems you might run into:
http://osdir.com/ml/chromium-extensions/2011-05/msg00261.html