Skip to main content

Ralsina.Me — Roberto Alsina's website

De Vicenzo: A much cooler mini web browser.

It seems it was on­ly a few days ago that I start­ed this projec­t. Oh, wait, yes, it was just a few days ago!

If you don't want to read that again, the idea is to see just how much code is need­ed to turn Qt's We­bKit en­gine in­to a ful­ly-fledged brows­er.

To do that, I set my­self a com­plete­ly ar­bi­trary lim­it: 128 lines of code.

So, as of now, I de­clare it fea­ture-­com­plete.

The new fea­tures are:

  • Tabbed brows­ing (y­ou can ad­d/re­­move tab­s)

  • Book­­marks (y­ou can ad­d/re­­move them, and choose them from a drop-­­down menu)

This is what al­ready worked:

  • Zoom in (C­tr­l++)

  • Zoom out (C­tr­l+-)

  • Re­set Zoom (C­tr­l+=)

  • Find (C­tr­l+F)

  • Hide find (Esc)

  • But­­tons for back­­/­­for­ward and reload

  • URL en­try that match­es the page + au­­to­­com­­plete from his­­to­ry + smart en­try (adds http://, that kind of thing)

  • Plug­ins sup­­port (in­­clud­ing flash)

  • The win­­dow ti­­tle shows the page ti­­tle (with­­out brows­er ad­ver­tis­ing ;-)

  • Progress bar for page load­­ing

  • Sta­­tus­bar that shows hov­­ered links URL

  • Takes a URL on the com­­mand line, or opens http://python.org

  • Mul­ti­­plat­­form (works in any place QtWe­bKit work­s)

So... how much code was need­ed for this? 87 LINES OF CODE

Or if you want the PEP8-­com­pli­ant ver­sion, 115 LINES OF CODE.

Be­fore any­one says it: yes, I know the ren­der­ing en­gine and the tool­kit are huge. What I wrote is just the chrome around them, just like Aro­ra, Rekon­q, Ga­le­on, Epiphany and a bunch of oth­ers do.

It's sim­ple, min­i­mal­is­tic chrome, but it works pret­ty good, IMVHO.

Here it is in (bug­gy) ac­tion:

It's more or less fea­ture-­com­plete for what I ex­pect­ed to be achiev­able, but it still needs some fix­es.

You can see the code at it's own home page: http://de­vi­cen­zo.­google­code.­com

El Barto / 2011-03-06 03:55:

Why Ctrl+= for Reset Zoom instead of Ctrl+0 like in every other browser? :-)

Roberto Alsina / 2011-03-06 11:03:

Good question :-)

Rodney Dawes / 2011-03-06 04:20:

You didn't write plug-in support. In fact, I did a lot of it. :)
Setting the WebSettings plugins_enabled to True doesn't count as a feature.

Does your URL entry autocomplete from bookmarks? Is it smart, or is it just dumb default Entry autocomplete behavior? Printing? Cookies? Keyring?

Roberto Alsina / 2011-03-06 11:07:

It completes from the WebView's URL history, so no, not default autocomplete behaviour . Right now it's buggy in that it completes only from that tab's history, but that's easy to fix, same as adding the bookmarks to the completer.
Having it complete from the web page titles is trickier.

Update: now there is a global autocompleter that also includes the bookmarks. It could be made much smarter, matching somewhere else than at the beginning of URLs, matching titles, etc, by reimplementing QStringListModel.match() but that's boring ;-)

Of course I know I did not write plug-in support, I did not claim I did either! (I am getting tired of everyone thinking they are clever by figuring out that I am using WebKit, really ;-)

Printing? Who prints things anymore? Niche feature!

It has cookies, but doesn't persiste them between sessions (should be doable).

It has no keyring support.

Rodney Dawes / 2011-03-06 15:06:

Well you are listing plug-in support as a feature amidst the other ones you did write. So it sort of implies that you are doing something special for it.

And people print things. Especially after checking in for a flight. Also, I always print receipts to PDF.

And persistent cookies is quite important. As is keyring password saving.

The only real way you're goign to get a totally feature full modern browser in 128 lines of Python, is if you do all the UI in JavaScript instead. :)

Roberto Alsina / 2011-03-06 15:13:

I specifically called that list "things that work", not "things I wrote". I don't see Safari or Chrome saying they don't have HTML4 rendering because that was already in KHTML before it was forked ;-)

I could implement printing the page to PDF in ... ok, maybe 10 more lines, and maybe another 15 for persistent cookies, so both are doable within the constraints. I will see if I have a moment later today :-)
updated: I added print to image, print to PDF is more or less the same.

Keyring support seems to be much more difficult.

Ramiro Algozino / 2011-03-06 15:37:

Chrome/mium didn't have printing support for a while.. soo.. ;-)

Roberto Alsina / 2011-03-06 16:14:

I seriously underestimated Qt. Full print support is done, including previewing and printing to PDF: 2 lines ;-)

Roberto Alsina / 2011-03-06 21:25:

Full printing support (PDFs and real printers) and persistent cookies are now on SVN. They added about 10 lines of code :-)

Diego Sarmentero / 2011-03-06 10:45:

Yo hace un tiempo había hecho un navegador web en Python+PyQt en 60 lineas, que tenia un par de cosas igual, por ahí podrías agregarle que cuando escribas palabras sueltas (que no tengan forma de url) en la barra de navegación, te haga la búsqueda en google derecho como hace chrome, acá tendrías ese código:

http://pastebin.com/y11LdrQU

Y está es la versión que yo había hecho, esta el código tanto para C++ y Python:

http://utopia555.blogspot.c...

Saludos!