ThomazPom / Moz-Ext-UltimaDark

Web Extension that uses agressive technique to get dark mode everywhere
110 stars 6 forks source link

Some websites use serviceWorker to cache, causing dark mode to not apply #82

Open gunir opened 2 months ago

gunir commented 2 months ago

Example: https://voz.vn/

Try to navigate to some random pages, and back/forward...

And you will see something like this: image

By disabling serviceWork, adding those rules to uBlock you fixed this issue: *$csp=worker-src 'none',domain=~example1.com|~example2.com

Go to about:serviceworkers and Unregister voz.vn

Or you can use this script: https://greasyfork.org/en/scripts/482724-reject-serviceworker-auto

So what can we do ?

Implement our method to disable serviceWorker, or finding a way to bypass it (unlikely).

ThomazPom commented 2 months ago

Thanks for the suggestion about disabling service workers. I wasn’t aware of that technique, and it’s interesting.

I’m considering whether we can pursue caching all functions related to content saving as I do now for darkening content. Your idea of giving users the option to disable service workers globaly or per site is feasible and will be a useful addition.

gunir commented 2 months ago

Thanks for replying, I hope you'll continue to develop this addon, it's the current most promising Dark Mode we've had before, faster than native, as someone explained here.

I’m considering whether we can pursue caching all functions related to content saving as I do now for darkening content.

I think this would be the best case scenario. Making dark cacheable would improve performance further I think.

Your idea of giving users the option to disable service workers globaly or per site is feasible and will be a useful addition.

It'll be pretty useful for debugging and fixing quick and dirty issues, because serviceWorkers can cause some really wierd issues to addons, uBlockOrgin had to deal with them some ways.

ThomazPom commented 2 months ago

I'm surprised and glad to see that it has garnered interest and is useful to reddit users, I've commented the post.

It's important to note that it's an unfinishable project with numerous complexities, and you are right when you say it be pretty useful for debugging and fixing obvious issues, even by dirty methods like service workers disabling to improve quickly by a lot user experience.

ThomazPom commented 2 months ago

@Vintagemotors FYI

ThomazPom commented 2 months ago

Disabling service workers for UltimaDark users is the way to go for now.

I created an option to allow users to keep service workers if they choose. Losing service workers is not a big deal since all service worker-based sites must work in private windows, which should never support service workers for privacy reasons. These websites have fallback mechanisms to handle these cases.

I explored many ways to continue ctching all functions related to content saving inside service workers, as I currently do for darkening content, because I think it’s a valid approach. However, a strange behavior of the WebRequests API prevents me from intercepting and editing service worker scripts. To be sure, I asked the Mozilla Firefox team in this bug report.

See edits in version 1.5.48.

gunir commented 2 months ago

I created an option to allow users to keep service workers if they choose. Losing service workers is not a big deal since all service worker-based sites must work in private windows, which should never support service workers for privacy reasons. These websites have fallback mechanisms to handle these cases.

I agree, disabling serviceWorker is pretty safe, not totally safe unless the website is badly coded.

I explored many ways to continue ctching all functions related to content saving inside service workers, as I currently do for darkening content, because I think it’s a valid approach. However, a strange behavior of the WebRequests API prevents me from intercepting and editing service worker scripts. To be sure, I asked the Mozilla Firefox team in this bug report.

Worst case scenario I think we could still possible to inject and override serviceWorker object to tamper and modify serviceWorker file before sending to Firefox.

I remember I've done something like this before, read and convert serviceWorker file to blob, and feed to register.

Line 61 of this script demonstrate how to fetch serviceWorker file content -> modify -> convert to blob -> feed to serviceWorker.register.

Hope this is helpful. Thanks a lot of improving this addon.

Vintagemotors commented 2 months ago

@Vintagemotors FYI

Sorry I didn't notice when this project became active again - I'm checking regularly again now.

ThomazPom commented 2 months ago

@Vintagemotors 😉 I’m happy to see you again 😄 I’m implementing your WhatsApp advice: releasing versions less frequently and focusing on the most critical user experience issues. Meanwhile, I’m struggling to find a good algorithm for image editing. I’ve already found new techniques. to improve compatibily to diverse websites and released version 1.5.0 . I’ve already found and fixed some code mistakes that negatively impacted performance, which is great news since image editing was one of the main bottlenecks.

gunir commented 2 months ago

@Vintagemotors 😉 I’m happy to see you again 😄 I’m implementing your WhatsApp advice: releasing versions less frequently and focusing on the most critical user experience issues. Meanwhile, I’m struggling to find a good algorithm for image editing. I’ve already found new techniques. to improve compatibily to diverse websites and released version 1.5.0 . I’ve already found and fixed some code mistakes that negatively impacted performance, which is great news since image editing was one of the main bottlenecks.

Can I see the code of Image Editing ? I might be able to figure out something

ThomazPom commented 1 month ago

Hi @gunir, Thanks for your input! I wanted to clarify that the userscript is overriding workers, not service workers, so this will not help us. However, I've discovered the webRequestFilterResponse.serviceWorkerScript permission, which might allow us to handle service workers without needing to disable them entirely. I'll be testing this to see how effective it is and if it allows us to intercept styles in the UltimaDark way of doing things.

Regarding image editing, I'm currently dealing with some complex issues and some non-interesting non-working code. For now, you can look into imageWorker.js to get an idea of how it was done for quite some time. I'm trying to rewrite it all to make it less dumb. Once I have a better understanding, I'll share new details and ideas with you. I'm looking forward to discussing the potential possibilities once things are clearer.

Vintagemotors commented 1 month ago

Are there any sites that still have this issue or is it resolved?