📜 ⬆️ ⬇️

Browser! = Browser engine


Hello!


In this article, I want to share my thoughts on creating my own browser engine. We will look at current browsers and browser engines. Recall the Modest and find out its difficult fate.


This will be a series of articles in which we will create our own minimalistic browser engine. Each article will be supported by real code and examples.
After ten articles, you and I will have a minimum working version of the browser engine, which is very minimal. After that, if the fuse does not go away and there will be community interest, we will continue, and eventually we will get to JS.


And of course, the first thing you need to understand what the browser and browser engine.


Browser and browser engine


The existing world is hard to imagine without browsers. They are on many devices: computers, laptops, phones, game consoles. If you imagine a browser in the form of a machine, then the browser engine is all that is hidden under the hood of your car.
Browsers like cars can differ in appearance and content under the hood. Color, buttons on the panel, audio. Someone has a V8 engine under the hood, and someone has oil flowing there.


The browser integrates the periphery and provides the functionality allowing to manipulate the engine, its behavior, provides additional services.
The browser engine does all the dirty work: loading, processing, drawing data and all possible calculations.


Just like in cars. There is a salon in which there is a gas pedal, brakes and many switches useful and understandable to the user. And there is a large mechanical part hidden from the user under the hood.


Who creates browsers and engines


Many companies are developing their own browser: Google, Mozilla, Apple, Microsoft, Opera Software, Yandex, Rostelecom, Vivaldi Technologies, many of them ...


Each adds some of its own "chips", services to the created browser. For example, Yandex integrates its services, search.


With browser engines, things are radically different. Here is a list of engines, their developers and owners:



These are the main owners and developers of engines. Third-party companies help them in development under certain conditions.


For example, consider the most popular project from Google - Chromium. This project contains a Blink engine. Such companies as Intel, Facebook, IBM, LG Electronics, NVIDIA, Yandex help create this project. Full list can be found here .
The conditions on which companies help Blink / Chromium create are described in the Legal stuff section on the Chromium project site. In short, everything you create belongs (not exclusively) to Google.


Browsers from Opera, Yandex, Rostelecom and others use this particular browser engine. To be completely honest, statements like “we have our own browser” are not entirely true. Own services - yes, but everything else belongs to another company (s). And this other company provides its browser engine under certain conditions.


Browser Engine Licenses


Any open source code contains a license with a description of the conditions for using this code, and browser engines are no exception.


If at once and briefly: the license is bearable, right here out of the ordinary nothing. Except EdgeHTML which is closed. Legally draining a project to yourself and apparently developing / changing it will probably not work. Licenses call for mutual openness.


Blink


Open source, a branch of the WebKit engine. As with WebKit, four licenses are claimed:



The most popular browser engine. He is part of the Chromium project. It is based on Chromium create their own browsers.


According to the LICENSE file for the Chromium project, its primary license is 3-Clause BSD. But the project has a third_party directory (third parties, third party) containing many third-party code on which the project depends. In other words, without this code to collect the browser will not work. Each component has its own licenses different from what is specified in the LICENSE project:



Gecko


Open source. Declared one license:



Mozilla is actively developing companies and is used in its own browser - Firefox. Also used in the browser Tor Browser provides anonymous stay in the network.


As a basis for browser manufacturers, there is not much popularity.


Webkit


Open source. Four licenses are claimed:



Developed by Apple and used in its own browser company - Safari. Previously, many companies used WebKit in their developments, but after leaving the project and switched to Blink from Google.


EdgeHTML


Closed source code. Proprietary license.


The engine is used for Microsoft's browser called Edge, which replaced Internet Explorer. This is their new engine. The previous Trident (MSHTML) company has stopped developing.


Risks


Using a third-party engine generates obvious risks:


  1. Closing the source code
  2. The exit of key companies from development
  3. Code change license

No one can guarantee that the source code of the free browser engine will not be closed for public access. It is also possible exit of key companies from the development of a free engine, which is actually its closure.


Companies developing their own browsers should understand that everything will be "good" until they constitute a threat / competition to the developers of the original browser / browser engine. I think this is obvious. The company spends on the development of the engine its resources, but suddenly there is another company that using their engine captures the market. The reaction, I think, is obvious - look at the list of risks above.


"We will create a copy of the engine at the moment and continue to develop ourselves" - this is the answer from browser manufacturers on third-party engines. A big mistake, it won't work out just like that to continue the development of someone else's engine. That is, take the programmers and set the task for them - write the browser engine. Writing a browser engine is a complicated technological process. This is confirmed by a list of their owners.


For example, Microsoft creates its own engine, albeit closed. Google, together with Apple, developed WebKit, but later Google made fork and began developing its own Blink engine.


In this case, you need to understand that the browser engine is constantly evolving. Specifications are constantly updated, new features are added, current ones are improved. This is a living job. If you take any engine for the current date and just use it for your browser, then, in about a year or two, the browser on this engine will become obsolete.


Adaptation of engines


There is a problem of adapting a third-party engine to the needs of its own browser. Not a lot of resources are spent on adaptation. At the same time, you need to understand that browser engines are frequently updated, which creates systematic problems when integrating into your own browser.


Own engine


First of all, you should answer the main question - why create your browser engine? Or rather, who does not need to create your own engine?


You should not create your browser engine if:



At the moment there is no difficulty to create your own browser on a third-party engine. They were created quite a few and somehow stand out among all this mass can only create a browser on its components exclusively, on its own engine.


Should I develop an engine for "earnings" to create a startup?


This question is rather to the scope of its application. I see several directions:


  1. Actually, the creation of a full browser. Cooperation with search engines, various services. Creation of special versions for state structures.
  2. Market IoT (Internet things), as well as an adaptation for televisions, consoles, portable devices.
  3. Services on individual browser components. For example, smart analysis of site content for risks: forbidden comments, posts from users, and so on. Technical analysis of sites.
  4. Sale of the engine. The easiest thing to write a company.

In addition, the prestige of the developer company browser engine is much higher than that of clones. Just like a technology company. This affects the company's popularity and attractiveness for existing and future employees. But this is more about ambition, to get on the same list with companies such as Google, Mozilla, Microsoft.


Conclusion


Without a doubt, creating a browser engine is a complex process and requires significant resources. Approach to this development is necessary very seriously and with a clear development plan. In addition, this is not the product of the profits from which you can get at an intermediate stage of development. Yes, individual components can be adapted to the needs of companies, but I am sure that this approach will only take time and significantly delay development.


The development of the browser engine is highly dependent on the method of its development. What will it be: open, closed?


I am sure that if a company develops a browser based on a third-party browser engine, then it should seriously consider the prospect of creating its own.


Companies far from browsers can also develop browser engine development, and not just to create a browser. If the final product is a full-fledged browser engine superior to the existing ones, then it will be in demand. Applications have been described above.


Cycle of articles


  1. Browser! = Browser engine
  2. Browser engine. Architecture, work with memory.
  3. HTML parser. Tokenization, processing tokens, building a tree.
    We write your parser. What are the stages of parsing HTML, what is the difficulty and how to disperse the HTML parser several times.
  4. HTML encodings. How to determine how to convert.
    We will write our encoder and discuss the situation.
  5. CSS parser and CSS modules. Tokenization, processing tokens.
    Create your CSS parser. Let us analyze the main aspects of CSS processing. Find out what the difficulty is, what resources are spent on and how to write the fastest CSS / module parser.
  6. CSS parser. Grammar.
    We write our own Grammar for CSS modules forming fast, human-readable code.
  7. CSS Selectors. As arranged, a quick search for HTML elements by selectors.
  8. Layout. We cross HTML and CSS.
    Assign CSS properties to HTML elements. Let us analyze the order of assignment, priorities and what to do if the CSS is constantly changing.
  9. Layout. Streams. Support for CSS display: block properties.
  10. Fonts. How to calculate the size of characters, lines.
    Let's write your font parser. We learn what baseline, descender, x-height are, how symbols are stored and dive into the topic of calculating the size of symbols.
  11. Layout. Support for CSS display: inline properties.

Fate Modest


Some readers may know that I am developing a browser engine. In my publications you can find previous articles on this topic.


Unfortunately, the project Modest had to be completed. For a while, the project developed in the company in which I had previously worked. I had to leave the company. There were disagreements that prevented further development of the project. Normal workflow, it happens.


Despite the fact that I have all the rights to Modest, nobody claims the code (the papers are signed), I decided to “bury” it. So that no one has any false sensations. Here we must understand that all the main code that has developed outside the company (mycore, myhtml) is buried. But there is a plus, perhaps I became a little smarter.


I spent a lot of time studying specifications, realizing them, searching for optimal algorithms, writing drafts (prototypes), creating myhtml (the fastest html parser) in my free time, and I can’t just throw away this topic. Many weekends, holidays, evenings, nights were spent.


Now I am developing a new browser engine. Development from scratch. He has no name yet, only code - lexbor. The whole framework has already been written: working with memory, general algorithms, and future architecture. As always, more and more beautiful than it was. In general, I have the most important thing: technology and a clear vision / understanding of how and what to develop.


One I can not pull such a project. If I don’t find support (financing), then I’ll stop development and join the existing co-driver to the existing open engine (Blink or Gecko). I will try to be a volunteer there and realize my ideas. I do all this only during off-hours.


Here, apparently, there should be a picture “you should fight evil, and not join it”.


Thanks for attention!


PS: All errors in lichku or considered copyright style.


')

Source: https://habr.com/ru/post/349512/


All Articles