Page 1 of 1 [ 6 posts ] 

AngryAngryAngry
Velociraptor
Velociraptor

Joined: 11 Feb 2016
Age: 42
Gender: Male
Posts: 495
Location: New Zealand

24 Apr 2017, 4:53 pm

I'm sick of websites that jump all over the show (probably loading ads), websites that are lagged by ads - especially on mobile burning the data & battery.
Also ads opening windows, or tabs when you are trying to play a browser game!
(Yes I'm using ad blockers).
And many other annoying things.

I wish to create a web browser from scratch.
I know, it would be easier to make an Operating System!
But I just want to start out small, HTML renderer and a simple GUI interface with a few Settings.
Not even wanting SSL encryption or anything. It will just be a little project for myself.

I wish to use C (not C++, definitely not Java, ruby whatever).

I just need to know where I can begin.
I have Allegro for the GUI interface stuff.



mr_bigmouth_502
Veteran
Veteran

User avatar

Joined: 12 Dec 2013
Age: 26
Gender: Male
Posts: 6,993
Location: Alberta, Canada

25 Apr 2017, 5:31 am

Install Firefox ESR
Install uBlock Origin
????
Profit.

That's how you get a usable browsing setup. 8)


_________________
Every day is exactly the same...


Chichikov
Veteran
Veteran

User avatar

Joined: 27 Mar 2016
Age: 45
Gender: Male
Posts: 1,151
Location: UK

28 Apr 2017, 7:13 am

This is one of those things where if you have to ask it's probably beyond you.

I'd start by first writing code to download a file via http, you can find the code for that easily enough, just standard socket stuff but you'll need to understand the http protocol but that's trivial too.

Next you'll need an html parser that turns that htttp into a document object model (DOM). You could probably have a decent stab at that but you'd have to go over the html RFC to make sure you're doing it properly and that's a couple of thousand pages of standards. But you could probably get away with the common-sense basics anyway but you'll need to cater for invalid and improperly formatted html too, especially if you are practising on real websites, but if I was you I'd start with rendering my own html so you know it is simple and well-formed.

Now you have your html into a DOM you can traverse that DOM to find other resources that need to be loaded such as images, css files, js files and so on. Again if I was you I'd start with ignoring css files and stick to plain basic html. At this point it is a case of interpreting the DOM you have in a visual manner.

When it comes to supporting links you'll also need to maintain cookies, again looking at the RFCs to make sure you're doing it properly so that will involve writing what is called a cookie container.

If you're planning on supporting actual web pages you'll need a CSS parser and you'll need to interpret and apply that CSS too so it's back to more thousand page RFCs.

Now let's talk javascript, you'll need to write a javascript parser and interpreter apply it.

That'll probably take you a few years to get to a somewhat reasonable state so now let's turn to your original intentions. If you want to stop annoying things like ads, ads are just javascript so how do you know what it "proper" javascript and what script is there for adverts, pop-ups etc? That's what pop-up and ad blockers do, they focus on that single problem and it normally runs off of maintained lists of what domains etc ads are served from, or an interpretation of what the js is doing.

If this is just a C learning exercise then fair enough, but if you want something useful you're probably better looking at writing a browser add-in that attempts to rectify some of the things you find annoying about web browsing, ie another ad blocker. That would be a far more manageable a task.



saxgeek
Veteran
Veteran

Joined: 18 Jul 2015
Age: 24
Gender: Male
Posts: 730

28 Apr 2017, 10:08 pm

I wouldn't recommend writing a web browser unless you've got tons of time on your hands and are a really experienced programmer. There are quite a few simple open source web browsers in C that you might be able to look at. Netsurf is a pretty good graphical browser, and is written entirely in ANSI C, and meant to be extremely portable. Most of the text based browsers like lynx and w3m are also written in C. All of these browsers have very minimal support for Javascript (if at all), so most of those modern, bloated sites which depend on Javascript won't work properly. Netscape was also written entirely in C, though it's closed source. There's a fairly minimalist browser called surf which is less than 2000 lines of C code, though it uses WebkitGTK as its rendering engine.

If you're planning on creating a browser from scratch that's comparable to Firefox or Chrome, then forget about it. Those are extremely large scale projects which require thousands of man-hours. A single person would not be able to do something like that from scratch.



AngryAngryAngry
Velociraptor
Velociraptor

Joined: 11 Feb 2016
Age: 42
Gender: Male
Posts: 495
Location: New Zealand

29 Apr 2017, 1:08 am

Thanks Chichikov, now I have a starting point. Yes, not wanting to do CSS or Javascript just yet.
But that info is great for when I have to.

Cheers Saxgeek, I'll definitely check those browsers out, to see if they can be useful for some browsing.

It is just a long term project, great for testing my C programming skills.



K_Kelly
Veteran
Veteran

User avatar

Joined: 18 Apr 2014
Age: 28
Gender: Male
Posts: 1,452

30 Apr 2017, 7:10 pm

I know I'm just beginning to learn to program in C from a book (I'm in the middle of chapter 3 :lol: ), but the previous poster gave me this idea. Why not write code for an existing minimal browser project?