The 1.2Kb python browser script

It’s time for another round of name-that-browser.

You can comfortably ignore the blue box in the upper left hand corner. This was meant to be a dual-purpose screenshot, showing the mystery browser on the right, along with mplayer playing a conventional DVD rip in Musca on a 300Mhz Celeron. Unfortunately, for reasons unbeknownst to mortal man, I got a blue box there rather than an action shot from the movie, which defeated half the purpose. 😦

But there are no tricks or gimmicks at work here, except to say that the browser is all of about 1.5Kb on disk, written in python and has webkit as its core. No toolbars, controls, address bar or menus, save the right-click menu that appears with some very primitive options in it.

And the answer is … I don’t know.

juancarlospaco posted it in reply to a question about lightweight browsers, and considering it’s just a 42-line python script, it’s probably a contender for lightweight champion, graphical division.

The name, however, remains a mystery to me. Perhaps it’s a well-known python exercise, or just a sample code snippet. In any case, you’re looking at it in Arch, with nothing more than gtk2 and the pywebkitgtk package from community installed. It’ll get 100/100 on the Acid3 test, renders images and fonts precisely and beautifully, and as you can see in that picture, can run at 300Mhz alongside Xorg, mplayer, alsaequal, alsamixer and Musca … and everything is hovering around 64Mb of memory total. Impressive.

But what’s the use in that? What good is a control-less browser window that needs to be fed a URL from the command line, a la python ?

Well, if you’re one of those half-and-half tiling desktop users who prefers a console-only arrangement against X (like Awesome or xmonad or dwm) it should be fairly obvious. Here’s a worthy replacement for heavyweight graphical browsers that won’t encumber a running system and still give you a graphical page display.

So if you’re torn between elinks and Firefox, this might serve as a decent middle-ground. It’s guiltless: None of the lard that comes with Firefox, and yet you still get accurate and faithful page displays.

I could also see where this might be useful for page designers or web coders, who need something that can jack up a page quickly, then drop out of sight. Instant page view, so to speak. I’m sure there are other possibilities here that I haven’t thought of, that you could offer.

Now if only I knew the name. … 😐

P.S.: Just for the record, because I have a feeling I’m going to be looking for the code in the future. …

#!/usr/bin/env python
import sys
import gtk
import webkit
DEFAULT_URL = '' # Change this as you Wish
class SimpleBrowser: # needs GTK, Python, Webkit-GTK
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect('delete_event', self.close_application)
        self.window.set_default_size(350, 20)
        vbox = gtk.VBox(spacing=5)
        self.txt_url = gtk.Entry()
        self.txt_url.connect('activate', self._txt_url_activate)
        self.scrolled_window = gtk.ScrolledWindow()
        self.webview = webkit.WebView()
        vbox.pack_start(self.scrolled_window, fill=True, expand=True)
    def _txt_url_activate(self, entry):
    def _load(self, url):
    def open(self, url):
        self.window.set_title('%s' % url)
    def show(self):
    def close_application(self, widget, event, data=None):
if __name__ == '__main__':
    if len(sys.argv) > 1:
        url = sys.argv[1]
        url = DEFAULT_URL
    browser = SimpleBrowser()

P.P.S.: The title of this post has a typo in it; that should say 1.5Kb, like it does everywhere else. 😳


28 thoughts on “The 1.2Kb python browser script

  1. Sam Weston

    Really cool script. However I get a “AttributeError: ‘module’ object has no attribute ‘WebView'” error on Ubuntu Lucid despite having python-webkit installed. I can’t figure out why 😦

    1. K.Mandla Post author

      If you cut and paste it from above, try it one more time. I forgot when I posted it this morning that, in its infinite wisdom, will parse out some characters and convert them to their html equivalents even if they are inside sourcecode tags. In other words, there was a character or two in there that appeared as ampersand-g-t-semicolon, when it should have been a greater-than symbol. No guarantee that’s the problem, but it’s one less possibility to consider. to the rescue … again. … 🙄

      1. Sam Weston

        Still no luck I’m afraid. Probably something to do with the way Ubuntu packages webkit.

        1. Sam Weston

          I am running a version of webkit from the webkit-team ppa so I can run the latest version of midori. I guess that’s probably where the problem is.

  2. Greg

    That’s what uzbl was made for too, to give an example. And then to that little 42 (coincidence?) line script you add whatever the hell you want, and it becomes a modular web browser.

  3. Oz Nahum

    Hi ,
    Thanks for the browser, until now i’ve used a simple script with just pyqt+webkit. But I prefer gtk+ (don’t ask me why though)…

    It’s also display better css then midory.

    It’s also very easy to add some bookmarks … just a text files a side 🙂

    Just a note for fixing a simple bug:

    typing $python
    every time is abit annoying, so I modified line 36 to:

    url = ‘http://’+sys.argv[1]


  4. Gaute

    Add this line and you will also have an entry box:

    — 2010-05-24 12:08:50.000000000 +0200
    +++ 2010-05-24 12:09:43.000000000 +0200
    @@ -16,6 +16,7 @@
    self.scrolled_window = gtk.ScrolledWindow()
    self.webview = webkit.WebView()
    + vbox.pack_start(self.txt_url, fill=True, expand=False)
    vbox.pack_start(self.scrolled_window, fill=True, expand=True)
    def _txt_url_activate(self, entry):

    the entry box was already there, i just added it to the vertical box.

    – gaute

  5. Thomas

    Interesting to see how easy it is to set up a webkit view. Looks very inviting to just play around with the code and add some extra fluff.

    Great blog by the way, your feed has been the first thing I go to in my reader for a long while now.

  6. Pingback: Hoy en minimalismo: Navegador para Linux en 1.2Kb | Seamos realistas…

  7. llivv

    install python-webkit
    fix unexpected indent line # 2
    change google to duckduckgo
    and it’s playung youtube HD trailers
    not sure yet if it’s using
    flashplugin = delicious

  8. Pingback: El Rincón de Jorgicio » El navegador más simple y liviano del mundo pesa 1.2 KB

  9. Pingback: Naveador web mínimo: Solo 1.2Kb « Un Bioinformatiquillo

  10. maxibon

    Is it possible to get this to work on windows because in the code it says

    class SimpleBrowser: # needs GTK, Python, Webkit-GTK

    I mainly use ubuntu but it would be great if i can get it to work on multi platforms.

  11. Pingback: Navegador para Linux que pesa 1.5 Kb | klicxel: palabras fuertes de sujetos extraños

  12. Pingback: Navegador para Linux que pesa 1.5 Kb

  13. jxlxl

    if it says module xx not found, try env python2.
    you might have python 2 & 3 installed, and e.g. webkit gtk is python2, but bin/python linked to python3.

  14. Pingback: Nice browser, but that name … « Motho ke motho ka botho

  15. Pingback: ngincat: Four lines of bash, plus netcat | Inconsolation

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s