<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Avdpro Pang</title>
    <description>The latest articles on DEV Community by Avdpro Pang (@avdpro).</description>
    <link>https://dev.to/avdpro</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F812414%2F6af62a3e-e7f6-4860-9f0e-037383354c46.jpg</url>
      <title>DEV Community: Avdpro Pang</title>
      <link>https://dev.to/avdpro</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/avdpro"/>
    <language>en</language>
    <item>
      <title>How to patch browsers to  become modern OS?</title>
      <dc:creator>Avdpro Pang</dc:creator>
      <pubDate>Tue, 22 Feb 2022 21:20:00 +0000</pubDate>
      <link>https://dev.to/avdpro/how-to-patch-browsers-to-become-modern-os-2ckb</link>
      <guid>https://dev.to/avdpro/how-to-patch-browsers-to-become-modern-os-2ckb</guid>
      <description>&lt;h2&gt;
  
  
  Can I Call Browser "OS"?
&lt;/h2&gt;

&lt;p&gt;Modern browsers become more powerful day by day in past decades. Now, even OS can be run inside of web pages(Game Console, Win32, DOS, emulators). In this way, can we call browser "OS"? Probably: &lt;strong&gt;No&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
So, what's different between Browser and OS, or, what's &lt;strong&gt;missing&lt;/strong&gt;? I took an investigation on this. &lt;/p&gt;

&lt;h2&gt;
  
  
  What Components Does a Typical OS Have?
&lt;/h2&gt;

&lt;p&gt;I should have learned this in school, but... Let's ask google.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--28d0i94a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t0qpjesymrlof2c93sdx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--28d0i94a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t0qpjesymrlof2c93sdx.png" alt="Google" width="880" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After reading 3 great articles, I summarized it to:&lt;/p&gt;

&lt;p&gt;Core components: [1]File System, [2]Process Management, [3]Memory management, [4]I/O Device Management  &lt;/p&gt;

&lt;p&gt;Additionally, "User oriented OS" needs: [5]GUI System, [6]Multitasking, [7]Network System, [8]Security Management.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wlSKihpW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b7fibnjuyzy0nwfj7w43.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wlSKihpW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b7fibnjuyzy0nwfj7w43.png" alt="OS Components" width="880" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, 8 components in total. Less than you expected, isn't it?&lt;/p&gt;

&lt;h2&gt;
  
  
  What's Missing?
&lt;/h2&gt;

&lt;p&gt;I looked into browser of those components. They are in several states: &lt;br&gt;
👍 : Check = 3 components&lt;br&gt;
👉 : Partly check = 4 components&lt;br&gt;
👎 : Missing = &lt;strong&gt;1 component&lt;/strong&gt; &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;Status&lt;/th&gt;
&lt;th&gt;Note&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;GUI System&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;👍&lt;/td&gt;
&lt;td&gt;After years competing each other, browsers are all superb at GUI.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Memory Management&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;👍&lt;/td&gt;
&lt;td&gt;Although eating them a lot, browsers handle memory not bad.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Security Management&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;👍&lt;/td&gt;
&lt;td&gt;Not like the old days, browsers are more secure.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Network System&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;👉&lt;/td&gt;
&lt;td&gt;Browsers are great at &lt;strong&gt;fetch&lt;/strong&gt; but not so good at &lt;strong&gt;serve&lt;/strong&gt; in network point of view.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Process Management&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;👉&lt;/td&gt;
&lt;td&gt;There are no &lt;em&gt;real process&lt;/em&gt; in browser. But we can think every &lt;strong&gt;&lt;em&gt;window (iframe) as a process&lt;/em&gt;&lt;/strong&gt;. And they are been greatly managed.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Multitasking&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;👉&lt;/td&gt;
&lt;td&gt;Like process management, we have pages, iframes, web-workers to work around.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;I/O Device Management&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;👉&lt;/td&gt;
&lt;td&gt;We really can't access those device in browser. But most of their function can be accessed via modern Web API like Web Audio, MediaStream, etc.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;File System&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;👎&lt;/td&gt;
&lt;td&gt;Normally, browsers' files come from web site by download. They can't be modified or share access between pages. Although there is a &lt;em&gt;File System Access API&lt;/em&gt;, it only limited supported by Chrome.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Make the Patch?
&lt;/h2&gt;

&lt;p&gt;To make browsers be more like modern OS, the major missing component is the &lt;strong&gt;File System&lt;/strong&gt;. &lt;br&gt;
There are a lot of open source "file-system" can be found on GitHub, but most of them are focused on &lt;em&gt;One Page&lt;/em&gt; and &lt;em&gt;temporary&lt;/em&gt; usage. So I started the project: &lt;strong&gt;OS like file-system for web pages&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Goal
&lt;/h2&gt;

&lt;p&gt;Make a file system for browser:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Compatible:&lt;/strong&gt; Work with Chrome(Edge), Safari and Firefox, desktop &amp;amp; mobile.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No Cheats:&lt;/strong&gt; Use only WEB standard API. No browser extensions or native apps need.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local:&lt;/strong&gt; Contents are stored in device local space, not server side.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Permanent:&lt;/strong&gt; Files should be kept in a permanent way.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross Page:&lt;/strong&gt; Within same domain, pages access the same contents. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API:&lt;/strong&gt; Provide API like node.js to access file-system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;HTTP(Better to have):&lt;/em&gt;&lt;/strong&gt; Files can be accessed with URL in browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Coding Execution
&lt;/h2&gt;

&lt;p&gt;To write such file-system, I met some challenges：&lt;/p&gt;

&lt;h3&gt;
  
  
  Choose Storage: IndexDB
&lt;/h3&gt;

&lt;p&gt;There are two types of permanent storage we can use: &lt;em&gt;LocalStorage&lt;/em&gt; and &lt;em&gt;IndexedDB&lt;/em&gt;. The first one is faster and support sync-operations, the second one is bit slower and does not support sync-operations.&lt;br&gt;&lt;br&gt;
The LocalStorage has two critical problems: size limit (around 10M) and cannot work in web workers. So, for a file-system, IndexedDB looks like the better choice.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sync Access to IndexedDB: Failed
&lt;/h3&gt;

&lt;p&gt;IndexDB only has async-API. I tried a several work-around to enable Sync-Access to IndexDB.  &lt;/p&gt;

&lt;p&gt;One of them is using &lt;strong&gt;sync-XMLHttpRequest&lt;/strong&gt; to fetch data from a Service-Worker that access the IndexedDB. It sounds promising, but only works on Firefox. Other crazier ideas all failed too...  &lt;/p&gt;

&lt;p&gt;After struggling with it a while, I gave up the idea of sync-access IndexedDB. Instead, the file-system will run mostly in async-access mode. When needed, certain path will be fetched into memory to perform sync-access. This is &lt;strong&gt;not perfect&lt;/strong&gt;.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Http Access: Well Done
&lt;/h3&gt;

&lt;p&gt;To enable direct URL access to files in the file system. I learnt to write a service worker.&lt;br&gt;&lt;br&gt;
I added one "/" at head of file path as the &lt;strong&gt;pathname&lt;/strong&gt; for URL. So file path "/docs/readme.md" turned to URL: "https://[domain]&lt;strong&gt;//&lt;/strong&gt;docs/readme.md". The service worker parses request URL, converts it to file-system path and respond with the contents from file system (indexedDB).   &lt;/p&gt;

&lt;h2&gt;
  
  
  The Result
&lt;/h2&gt;

&lt;p&gt;It has done a good job. All project goals are checked! It comes with a &lt;strong&gt;node.js fs API&lt;/strong&gt;.&lt;br&gt;
Based on the file system, I made some interesting Apps:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. File Manager
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O5jFqzza--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pkii9sjlwqr61erszqjx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O5jFqzza--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pkii9sjlwqr61erszqjx.png" alt="File Manager" width="880" height="568"&gt;&lt;/a&gt;&lt;br&gt;
It's very much like Windows Explorer and MacOS' Finder. Besides manage files, you can &lt;strong&gt;drag&amp;amp;drop or copy&amp;amp;paste native OS files&lt;/strong&gt; into the web file-system. &lt;/p&gt;

&lt;h3&gt;
  
  
  2. Terminal
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tkHTNV4n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/atd4nifx2dtljtj3xnn9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tkHTNV4n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/atd4nifx2dtljtj3xnn9.png" alt="Terminal" width="800" height="470"&gt;&lt;/a&gt;&lt;br&gt;
This is a UNIX terminal mockup in web. It supports commands like: ls, cd, mkdir, cp, rm, move, zip, unzip etc...&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Code Editor
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vzUUv8Sb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l3xkesg63ndjn2i7l6hw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vzUUv8Sb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l3xkesg63ndjn2i7l6hw.png" alt="Code Editor" width="880" height="561"&gt;&lt;/a&gt;&lt;br&gt;
Powered by CodeMirror, the code editor can edit HTML, Javascript, JSX, and other text files just like a modern code editors: syntax-highlight, block-fold, auto-complete, search-replace and more. I coded most apps and tools (the terminal, file manager, commands in terminal) with it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fastify Server in Browser
&lt;/h3&gt;

&lt;p&gt;With service worker, we can provide service. So I ported &lt;strong&gt;Fastify&lt;/strong&gt; framework to do that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try out
&lt;/h2&gt;

&lt;p&gt;You can try out the file-system and apps based on it at &lt;a href="//www.cokecodes.com"&gt;www.cokecodes.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My file system code git is here: &lt;a href="https://github.com/Avdpro/JAXDisk"&gt;GitHub:JAXDisk&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>serverless</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
