WebOS 2 Devlog #9: Implemented color accents and some browser improvements
I was originally going to do some debugging and finish of this project but i was looking through other peoples’ webos projects and realised there was much i could improve. I then got like a huge brainwave about new stuff to implement so ig it’ll be a bit longer before I ship this project. One of these ideas was adding color accents because right now my modern theme is limited only to a light pinkish color. Here are the changes i made:
Change 1: Accents
In the settings screen, i added an option to choose the system accents. I also gave some basic presets and added an option to pick a color by adding a color picker option. Implementing this was quite simple, just replace all hardcoded pink colors with –os-accent (which i added in css). I linked htis –os-accents attribute/class to the color that the user chooses in js and made ti that all the places where the accent pops up, the color variable there is replaced with –os-accents. So if the user changes the accent in settings, the places where –os-accent is set changes color automatically.
Challenge 1: Contrasting invisible text
The problem: Swapping a single hex code for an accent color that the user chooses breaks all translucent UI elements (like shadows). Furthermore, if a user picks a bright color (like Mint Green or Yellow), the hardcoded white text on the title bars becomes completely invisible.
The Solution:
I implemented a Hex-to-RGB engine that injects raw RGB values directly into the CSS :root. This solves the first part of the problem. To solve the text contrast issue, I implemented the WCAG Relative Luminance algorithm ( used a bit of outside help here iykwim ;)). The OS now mathematically calculates the perceived brightness of the user’s chosen color. If the relative luminance passes a threshold of 0.179, the OS flips the title bar text to pitch black so its legible comfortable.
Change 2:
i was just playing around in the webbrowser and exploring, and i found some stuff that needed to be fixed: when building a simulated web browser using tags, embedding sites like google resulted in a “Refused to Connect” error. These servers send an X-Frame-Options: DENY header. Because client-side JavaScript is legally blind to server headers, the OS couldn’t detect the block to show the custom error screen I made. I knew this error existed and knew this was a thing but only after experiencing it like a real user did i realise how annoyinf this was and it made my os seem broken.
Solution 1 (attempt):
I initially tried routing requests through a third-party API to read the headers, but ad-blockers and privacy shields just made the API requests not work, crashing the entire browser app (at least thats what i think is the cause).
The Solution:
I used a massive Regex blocklist, such that the browser now instantly intercepts requests to 99% of top-tier websites that block iframes (like youtube or google), and routs the user to a custom error page. (did these stuff with the help of some ai only)
Next Problem:
When a user searches Google inside the iframe and clicks a link in the embedded page, the OS address bar wouldn’t update. This is a browser restriction. Browsers mathematically lock JavaScript out of reading cross-origin URLs for security reasons. At this point i just stopped instead of trying to waste my time trying to break through some military grade (i think?) restrictions.
Change 3:
Before, only iframe compatible websites worked but i had an idea to route all queries (except the ones in websites format) through a google search. Apparently, google.com doesn work in iframe but the google search works. So now if i type hello world, it just redirects me to a google search page with hello world searched.
P.S. I made some other tiny changes aswell but i cant rlly remember them now sry