Testing “Safari” via Bash for Windows & JS

WebKit2GTK uses same Safari rendering and JavaScript engine

I’ve already talked about writing native applications with JavaScript and Gtk, covering Linux, my primary OS, and macOS too via Homebrew or Macports. What was missing at that time was a proper way to write the same app on Windows too.

WSL / Bash on Windows to the rescue

However, and somehow, developers managed to fill the gap through Xming, a good old Xorg port for windows and cross platform software written for Mac or Linux.

Connecting the dots together, we can assume writing GJS applications on Bash for Windows should be possible, right?

Upgrade Trusty to Xenial

To know which version is it, type the following in the console and read the output:

lsb_release -a

If it says 14 or “trusty” anywhere, you need to follow the only procedure that actually worked for me, found through this ticket.

Follow the instructions, and if once finished, closed, and reopened Bash you have issues, have a look at these two possible solutions. The one that worked for me was the following one, performed from the Command Prompt:

lxrun /setdefaultuser root

You should now be able to start Bash and do apt-get updateand other operations to be sure you have the latest.

If there’s some warning about some ignored file, feel free to ignore, or actually remove it.

Installing GJS and WebKit2GTK

sudo apt-get install libgtk3.0 libwebkit2gtk-4.0 gir1.2-gtk-3 gobject-introspection gjs

Theoretically, we could already use gjsbut if we want to see something, we’ll need a DISPLAYtarget. Type echo $DISPLAYto be sure there isn’t one already, and in such case add the display to your user env.

echo 'export DISPLAY=:0.0' >> ~/.bashrc

You can now restart bash or simply type export DISPLAY=:0.0and move on … but

Configuring Xming

You need to launch Xming before trying to use anything graphical on WSL.

Testing GJS

Hello World in GJS and Gtk3 for Windows

You can simply curlthe “hello world” or write it yourself, it’s that simple:

curl -LO archibold.io/test/gjs/hello

You can launch it directly as executable after a chmod a+x helloor simply launch through gjs hello.

If you don’t see the widget on top of the others, look your system bar, I’m sure something is blinking asking for attention.

Trying WebKit2GTK in all its glory

Another one is to bring a frame-less quick tester, or the same browser I’ve written in my old post, slightly re-adapted to use WebKit2 instead of WK1.

These are both on GitHub, but you can simply grab them via archibold.io.

curl -LO archibold.io/test/gjs/browser-bar

Have fun testing for Safari engines on Windows and JavaScript for native Gtk applications!

Web, Mobile, IoT, and all JS things since 00's. Formerly JS engineer at @nokia, @facebook, @twitter.

Web, Mobile, IoT, and all JS things since 00's. Formerly JS engineer at @nokia, @facebook, @twitter.