Do browsers provide any pre-render hook where you can apply changes to styles of DOM elements before they are rendered?
For example, I might want to change the color of anything that is red to green
This requirement is for a browser extension so the solution should work across different webpages. It is not trivial to override the style of an element while being agnostic of the source code as the style of an element is a result of the CSS and Javascript that runs on it and the mechanism is different for different websites. Ways that come to mind are:
- Parsing the CSS and Javascript of the web page to determine the styles of elements. This seems redundant as the browser is also doing it
- Scanning the DOM and checking the computed styles of each element and overriding stuff. This works but if elements change dynamically, we have to repeatedly scan for changes which might be heavy
So does such a browser hook exist? If not, what alternate approach would you recommend?