Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gunir opened this issue Aug 6, 2024 · 11 comments
Open

Comments

@gunir
Copy link

gunir commented Aug 6, 2024

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
Copy link
Owner

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
Copy link
Author

gunir commented Aug 6, 2024

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
Copy link
Owner

ThomazPom commented Aug 6, 2024

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
Copy link
Owner

@Vintagemotors FYI

@ThomazPom
Copy link
Owner

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
Copy link
Author

gunir commented Aug 18, 2024

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
Copy link
Collaborator

@Vintagemotors FYI

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

@ThomazPom
Copy link
Owner

@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
Copy link
Author

gunir commented Aug 26, 2024

@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
Copy link
Owner

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@ThomazPom @Vintagemotors @gunir and others