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. :oops:

About these ads

27 Responses to “The 1.2Kb python browser script”

  1. 1 Sam Weston 2010/05/24 at 7:03 AM

    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 :(

    • 2 K.Mandla 2010/05/24 at 9:44 AM

      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. … :roll:

      • 3 Sam Weston 2010/05/24 at 4:52 PM

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

        • 4 Sam Weston 2010/05/24 at 5:02 PM

          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. 5 Greg 2010/05/24 at 8:02 AM

    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. 7 zoev9 2010/05/24 at 8:14 AM

    Where did you find this little diamond among the dust? It’s perfect!

  4. 9 eckeroo 2010/05/24 at 8:23 AM

    Would a lot of work be required for it to play flash?

  5. 10 Oz Nahum 2010/05/24 at 1:40 PM

    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]


  6. 11 Gaute 2010/05/24 at 7:12 PM

    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

  7. 13 Thomas 2010/05/25 at 9:19 AM

    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.

  8. 14 pawnhearts 2010/05/25 at 6:44 PM

    check out my pywebkitgtk browser

  9. 15 James 2010/05/26 at 9:48 AM

    Really want a lightweight browser? Port that script to a compiled language. ;-)

  10. 16 steve 2010/05/26 at 7:45 PM

    That is absolutely brilliant. Thanks so much!

  11. 17 llivv 2010/05/27 at 2:18 AM

    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

  12. 18 maxibon 2010/06/27 at 6:04 PM

    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.

  13. 21 jxlxl 2010/11/17 at 5:35 AM

    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.

  1. 1 Hoy en minimalismo: Navegador para Linux en 1.2Kb | Seamos realistas… Trackback on 2010/05/25 at 1:06 PM
  2. 2 El Rincón de Jorgicio » El navegador más simple y liviano del mundo pesa 1.2 KB Trackback on 2010/06/03 at 10:47 AM
  3. 3 Naveador web mínimo: Solo 1.2Kb « Un Bioinformatiquillo Trackback on 2010/06/04 at 3:24 PM
  4. 4 Navegador para Linux que pesa 1.5 Kb | klicxel: palabras fuertes de sujetos extraños Trackback on 2010/07/26 at 12:17 PM
  5. 5 Navegador para Linux que pesa 1.5 Kb Trackback on 2010/09/10 at 7:27 AM
  6. 6 Nice browser, but that name … « Motho ke motho ka botho Trackback on 2011/02/07 at 9:08 AM

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s


Visit the Wiki!

Some recent desktops

May 6, 2011
Musca 0.9.24 on Crux Linux
150Mhz Pentium 96Mb 8Gb CF

May 14, 2011
IceWM 1.2.37 and Arch Linux
L2300 core duo 3Gb 320Gb

Some recent games

Apr. 21, 2011
Oolite on Xubuntu 11.04
L2300 core duo 3Gb 320Gb

Enter your email address to subscribe to this blog and receive notifications of new posts.

Join 405 other followers


This work is licensed under the GNU Free Documentation License. Please see the About page for details.

Blog Stats

  • 3,961,025 hits



Get every new post delivered to your Inbox.

Join 405 other followers

%d bloggers like this: