Python Web Browser on the way
I’ve spent a good chunk of my vacation working on some of what will become the internals of a web browser written in Python.
Some of the goals of the browser include:
- Full conformance to all DOM 2 Modules (and equivalent DOM 3 modules when they become recommendations). This goal is already about 60% done.
- Full conformance to CSS2.1, and eventually CSS3
- Javascript support.
- SVG and Canvas support
- Little or no explicit support for deprecated standards and technologies (yes, this is a feature).
The most important features, and thus the ones getting the most attention, will the standards compliance and JavaScript support. Standards compliance is important because I want this browser to be an example of a browser which people should take seriously. I won’t, however, do extra work because somebody out there decided to not follow the standard when designing their webpage. JavaScript support is important for the same reason. Nobody is going to take a browser seriously (or be able to use it for any modern website) if it doesn’t support JavaScript.
So far I’ve got a complete (but also completely untested) implementation of the DOM 2 HTML, which took me a good amount of time longer than expected.
I started with a good base: pxdom, a complete implementation of DOM 3 Core and LS (Load and Save), and implemented my additions on top of that. It’s still a separate module, though, but there are a few places where I rely on some of the implementation specific details of pxdom. I have plans to remove the dependency at some point so that I can swap in other DOM core implementations.
On top of that I built my DOM HTML implementation, and laid a little bit of groundwork for DOM StyleSheets and CSS. I’ll be using cssutils, which is a mostly complete python DOM CSS implementation. The cssutils version 0.9.4b1 was just released with mention of some sort of selector support being added in version 0.9.5, which will hopefully make it so I don’t have to do a full CSS cascade implementation myself.
I’m taking a break from working on DOM implementations now and moving back to something which will actually allow me to see results: the rendering engine. I’m starting with just a stub implementation of the ViewCSS interface which allows me to use the getComputedStyle function to get the default style for any given element. With that, I should be able to render any HTML document as if it had no style applied to it. Later on I will hopefully be able to use the upcoming selector support in cssutils to make getComputedStyle work as expected.
This browser is something that I’ve been wanting to do for a very long time. I even sort of started to implement the rendering engine a long time ago using pycairo as the backend. I’m going to stick with that because it seems to be an ideal rendering backend for webpages (which would explain why it will be the only thing used for rendering as of Firefox 3.0
), and for eventual SVG and Canvas support. Once I get to the part where I’m actually working on the user interface portion, I’m planning on writing a Python binding for glitz, which will provide the browser with OpenGL accelerated rendering by default.
Tags: Browser, css, dom, Programming, Python
December 31st, 2007 at 5:56 am
Regarding cssutils selector support: I started that, although I suspect it will take some time. The SVN version already has a property “specitivity” for a selector (almost done). The actual cascade will really take a bit of thinking as cssutils currently does not render anything nor is it possible to query the sheets at all. I am (of course) very interested in your ViewCSS implemenation, is the source of your browser available to play around with?
January 1st, 2008 at 10:58 pm
Sadly I haven’t gotten a chance to write any code for the ViewCSS class yet. As soon as I get a chance , though, I’m going to experiment with different ways of applying CSS selectors to the DOM tree.
As for the rest of the code, it needs some more cleaning up before I release it. Some of it was written quite hastily. I suppose I need to convert or write some test suite for actually testing my implementation.
Anyway, hopefully I’ll have something worth sharing some time this coming weekend. Or if there’s an ice storm in Round Rock tonight (actually a possibility), maybe I’ll do it tomorrow
Probably not, though…
January 8th, 2008 at 2:47 pm
I did use lxml’s CSSSelector method on a HTML which works great. An example is in the cssutils SVN, but I guess I release an early 0.9.5a soon which will have quite a few changes in it.
April 11th, 2008 at 6:06 am
[...] about to go hacking about in the monstrous labyrinth that is the Mozilla source code, so I’ve started my own browser project. It will probably never catch up with the other, “real” browsers, but it will keep me [...]
September 13th, 2008 at 2:07 am
[...] made some progress on my Python web browser. It’s nothing earth-shattering at the moment, but it does take all the text from a web page [...]