Raspberry Pi: Faster and Lighter Web Browsing with Luakit
April 2, 2013 10:31 pm 4 Comments
So enter Luakit. An extremely lightweight and highly configurable web browser. It is based on webkit and GTK+. Now, as lean and mean Luakit can be, its user-friendliness can’t be rated as high. Therefore I have created this guide to help installing Luakit and configuring some options that I think will help your user experience. I personally think this guide is needed because I had to do quite a bit of research to get it to work the way I want, close to a normal browser.The Raspberry Pi with its original Raspbian OS comes with Midori as its default browser. While Midori is already light in comparison with Chrome and Firefox, this is not light enough under many circumstances. There are a lot of times when I opened up a website and it locks up completely; mostly because the CPU is very busy. Now of course I can use Lynx as an alternative but that wouldn’t be cool.
Install Luakit
This is the easy part. Thankfully with Raspbian we won’t even have to compile Luakit from its source.
So open your terminal and simply do :
1 |
sudo apt-get install luakit |
Get the Basic Essential Plugins
The next thing you want to do is prepare the plugins location and download the essential plugins. This is important as we want to be able to switch useragent later on.
So create the plugins directory and go into the directory.
1 2 3 4 5 |
cd ~/.config/luakit mkdir plugins cd plugins |
After that clone Luakit plugins, this pack will contain things like user-agent changer and ad-blocker. Now, if you read my previous retro gaming article, you would have already installed git console needed to clone codes from Github.
1 |
git clone https://github.com/mason-larobina/luakit-plugins ./ |
Then prepare the Luakit configuration file.
1 |
cp /etc/xdg/luakit/rc.lua ~/.config/luakit/ |
Next we want to tell Luakit to include the plugins when starting up. Therefore open the rc.lua file that you just copied into your config directory with your favourite editors, be it VI or leafpad. Edit the file and add require “plugins” after the Optional user script loading. So your configuration file in that section will look like:
1 2 3 4 5 6 7 8 9 10 11 12 |
---------------------------------- -- Optional user script loading -- ---------------------------------- require "plugins" require "webinspector" -- Add sqlite3 cookiejar require "cookies" .....etc |
Start luakit to instantiate the plugins and generate the rc.lua file in the plugins directory.
You can type luakit anywhere in the terminal.
You’ll get an adblock error. Don’t panic, this is normal. To fix this you have two options: you can either download the list manually or simply disable adblock. We’ll take a look at both.
Disabling plugins you don’t need
cd ~/.config/luakit/plugins/Go into your plugins directory
Open rc.lua with your text editor. For example: leafpad rc.lua or vim rc.lua
Set plugins.policy = “manual”
Comment out the plugins that you don’t want.
For example in this instance we only want to use tabmenu (which will give us the ability to list all the tabs that we have open) and uaswitch (the user agent switcher that we will use to simulate mobile website).
So edit the plugins_to_load section:
1 2 3 4 5 6 7 8 |
plugins.plugins_to_load = { # "adblock.chrome", # "yanksel", # "adblock", "tabmenu", # "oldschoolkeys", "uaswitch" } |
Setup Luakit Ad-Block.
As an alternative to disabling this, you can download the ad blocker list. I’m sure this will affect the browser performance as it would need to do pattern matching, etc on each web page; which is why I disable this on my installation.
However if you want to enable this extension:
1 2 |
cd ~/.local/share/luakit/ wget https://easylist-downloads.adblockplus.org/easylist.txt |
Setup the Mobile Useragent
The Raspberry Pi doesn’t have as much processing power as your powerhouse machine, so you might want to consider using mobile useragent as the default. It may not look as pretty, but it will be easier on your Pi because some websites really have Javascripts that might bring the Raspberry Pi to its knees.
1 2 |
cd ~/.config/luakit/plugins/uaswitch/ leafpad ua_strings.lua |
Then edit the file to add a mobile useragent:
1 2 3 4 5 6 7 8 9 10 11 |
plugins.uaswitch.ua_strings.fakes = { ["mobile"] = "Mozilla/5.0 (Linux; U; Android 2.3; en-us) AppleWebKit/999+ (KHTML, like Gecko) Safari/999.9", ["inferfox"] = "Mozilla/6.0 (compatible; AppleWebKit/latest; like Gecko/20120405; };-> infernal_edition:goto-hell) Firefox/666", ["firefox_15"] = "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120427 Firefox/15.0a1", ["firefox_14"] = "Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20120405 Firefox/14.0a1", ["firefox_13"] = "Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20120403211507 Firefox/12.0", ["firefox_11"] = "Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko Firefox/11.0", ["ie10"] = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)", ["camino"] = "Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.6; en; rv:1.9.2.14pre) Gecko/20101212 Camino/2.1a1pre (like Firefox/3.6.14pre)", ["safari"] = "Mozilla/5.0 (Macintosh; PPC Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10", } |
Now we’ll set the mobile useragent as the default.
Open the init file, so:
1 |
leafpad init.lua |
In the load() section, modify interfox to mobile as we have defined previously.
1 2 3 4 |
function load() load_ua_strings() switch_to("mobile") end |
Add some scrollbars
By default luakit doesn’t come with any scrollbars. To scroll up and down you will use our mouse scroller but left and right will have to be done using your keyboard.
Open your luakit rc.lua
1 |
leafpad ~/.config/luakit/rc.lua |
Find the part where it says — Restore last saved session then add the scrollbars code before that section. So your settings should look like the following:
1 2 3 4 5 6 7 8 9 10 |
----------------------------- -- End user script loading -- ----------------------------- webview.init_funcs.show_scrollbars = function(view) view.show_scrollbars = true end -- Restore last saved session local w = (session and session.restore()) |
Changing your default homepage
Copy your luakit globals configuration to your .config/luakit/
1 |
cp /etc/xdg/luakit/globals.lua ~/.config/luakit/ |
Then open your newly created globals.lua with your favourite editor.
Change the homepage parameter into your preference.
Useful shortcuts
On with the Web Browsing!
i | Insert mode |
:o | Open a website |
:tabopen | Open in a tab |
ctrl + w | Close current tab |
i | Insert mode, you’ll be able to type into input boxes in the website |
esc | Reset to command mode |
:ua | Change useragent |
Simply start a terminal session and type luakit to start your new browser anytime. Have fun!
Tags: linux, luakit, Raspberry Pi, tips and tricksCategorised in: Fun computing, General Computing, Linux Tricks, Raspberry Pi