xcr
Posts: 2
Joined: Wed Dec 12, 2018 11:02 pm

Chromium and Raspbian lite, programmatic control

Wed Dec 12, 2018 11:35 pm

So, I've seen docs that detail running Chromium in Raspbian lite - in a "kiosk mode". Perfect!

Does Chromium have an API where I can communicate with the browser via something like a .net core app running in the background? I'd like to be able to direct the browser to html, js, and css resources locally as well as communicate with the page's JS with my .net core app to send it data/commands. Possibilities, other thoughts?

I can and do currently accomplish this with Win10IOT and UWP - but that's a TON of overhead, slow boot times, no GPU, and, it won't run on the compute module.

I guess worse case I could fire up an asp.net capable onboard webserver and do the heavy lifting there, but it would be much cleaner to communicate with the browser directly.

Andyroo
Posts: 4466
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Chromium and Raspbian lite, programmatic control

Thu Dec 13, 2018 10:09 pm

Just make sure you get the semi-skimmed version of Raspbian - the one with the GUI :D

Simplest way to send keystrokes is to send them to the x11 terminal session with the xdotool (as this allows mouse control) or you could drive it from uinput and Python or C.

A quick intro can be found https://theembeddedlab.com/tutorials/si ... pberry-pi/

Do you have to use a browser or could you use get and post commands and process the resulting text?
Need Pi spray - these things are breeding in my house...

Heater
Posts: 13291
Joined: Tue Jul 17, 2012 3:02 pm

Re: Chromium and Raspbian lite, programmatic control

Fri Dec 14, 2018 5:52 am

xcr,
I'd like to be able to direct the browser to html, js, and css resources locally as well as communicate with the page's JS with my .net core app to send it data/commands. Possibilities, other thoughts?
Easy. Just make your app into a web server and have it deliver all the html, js and css you want.

You can communicate between your app and any JS running in the page using GET/POST requests, XMLHttpRequest or use web sockets for continuous two way communication.
https://developer.mozilla.org/en-US/doc ... ttpRequest
https://developer.mozilla.org/en-US/doc ... ockets_API

I have no idea about .net but this is very easy to do in node.js
https://nodejs.org/en/

Or in Python using libraries like FLASK.

ghans
Posts: 7873
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Chromium and Raspbian lite, programmatic control

Fri Dec 14, 2018 5:59 am

Professional browser automation is done with Selenium and the WebDriver protocol.
The latter is already supported by Chromium AFAIK.

I am not convinced that an embedded webserver isn't the cleanest solution. The seperation between server and client is a positive, since you normally want to swap the client at will.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

xcr
Posts: 2
Joined: Wed Dec 12, 2018 11:02 pm

Re: Chromium and Raspbian lite, programmatic control

Fri Dec 14, 2018 10:44 am

Thanks for all the thoughtful replies and ideas. The last two days I've had my head buried in the computer, and all 5 of my monitors cluttered with chrome, visual studio, explorer, putty, winscp, etc windows...

My first thought was running a light webserver, then just having a browser load the page which would be generated via asp.net, then push whatever I needed to it via the code on the server. Having done quite a lot of server side web work, it seemed pretty natural. However....

Over the last two days, this is what I've done and it's working nicely with a test that just displays current time updating every second:
Installed Stretch Lite
Installed GPU drivers
installed x server
Installed Chromium
Jacked with Chromium config to enable GPU rendering
Installed .net core 2.1 (since I'm pretty proficient in .net technologies) - pulled in the selenium references via nuget
wrote a simple html page that has my base structure and loads appropriate js & css
wrote a .net core console app
config'd x to autorun my console app
console app uses selenium API to fire up chromium and load my html page
console app calls javascript functions in my js file to update page with whatever data I need, whenever it likes. Eventually the console app will be network aware and be able to receive data pushed from another machine, which can then manipulate the webpage, and even the RPi itself if necessary (i.e. force a reboot, change config, etc).

This seems very clean and very light weight. I could do this with a webserver and websockets using something like SignalR, but it seems like a lot of extra work vs what I had in my head and the way I accomplished this same setup on Win10IOT.

So with this setup, the client is the web browser, the "server" is my console app using Selenium as an API to then control the browser. I know Selenium was created for test automation, but I've found that if thought of as a browser API it's useful for many more applications.

With this configuration, I can re-use a TON of code and libraries I've already written - only now on Stretch instead of Win10 IOT. Much faster boots, much more flexibility, and probably, much more horsepower available since now I'm able to render the web page and any animations with the GPU.

There was some pain and suffering to be had along the way - probably mostly due to my limited and far between experience with Linux. My main hangup with Linux was how to fire up a "GUI" app (i.e chromium) using a console only OS. The answer to that was to run the lightweight Stretch lite, then install a bare bones x-server and use that to fire up a "kiosk" mode chromium window. Loving it! Thinking this will be the first of many projects of this type.

Return to “Other programming languages”