You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've already read issues regarding fast injection, and understand it's not possible.
I'm not sure if my issue is about "fast injection" or not, hence why i'm writing this, I'm also looking for advices.
I have a project that grab an external theme (.css) for Mastodon, and inject it inside the page.
I use MutationObserver's API on Firefox, and it just works fine.
Mastodon CSP's rules doesn't allow for raw injection of <style> tag, I'm forced to wait for meta header 'style-nonce', and get it's value to inject the page with the style's url.
I used to be able, during load time, to set <html> background value asap (it doesn't abid to CSP rules) so it wouldn't "flash" (ie : you're in dark mode and normal mastodon theme in light mode) as tag can be changed as soon as possible, we don't need to wait for the tag to exist. document.querySelector('html').style.setProperty("background", backColor, "important");
However, that's not enough, as of right now, to avoid flash on Mastodon, one needs to override <body> background value, instantly. I need to be able to detect and fetch the body tag as soon as possible, because the tag need to exist, unlike <html>.
For both Chrome and Safari, MutationObserver is rarely fired outside of "Cmd+Ctrl+R" (command that clear the cache).
MutationObserver is really reliable to fetch any tag in the <head>, I don't understand why.
I have a workaround which use requestAnimation frame to detect elements, but I can't manage to override fast enough to avoid the weird flash.
I hope I'm just missing something and there's a better way or API.
Thanks a lot for reading me.
EDIT :
I just wanted to add that I have other userscripts for other website, with no CSP protection, and injecting my custom css (embedded inside the userscript itself, this time) with :
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css.replace(/;/g, ' !important;');
head.appendChild(style);
}
and it does the flashing too. Which mean it's not injecting the style fast enough, it does work great on firefox though.
Apparently Darkreader has a way around that since applying dark theme doesn't do any flashing. I really don't know what I'm missing here.
The text was updated successfully, but these errors were encountered:
I think this should be posted in Discussions instead of Issues.
I'm not sure what you're looking for, but I think Mastodon has its own dark theme, so I'm not really sure how the FOUC you're talking about happens.
A good practice is to provide feedback to the project or the site itself for a first-party resolution, which is technically the easiest.
User script has greater latency than the extension itself because the extension needs to deal with user script metadata and a complex injection process.
We would like user script injection to be faster, but currently we are limited in what we can do.
Due to duplication and unclear question, I will close the issue, but you can continue to comment.
Hello,
I've already read issues regarding fast injection, and understand it's not possible.
I'm not sure if my issue is about "fast injection" or not, hence why i'm writing this, I'm also looking for advices.
I have a project that grab an external theme (.css) for Mastodon, and inject it inside the page.
I use MutationObserver's API on Firefox, and it just works fine.
Mastodon CSP's rules doesn't allow for raw injection of
<style>
tag, I'm forced to wait for meta header 'style-nonce', and get it's value to inject the page with the style's url.I used to be able, during load time, to set
<html>
background value asap (it doesn't abid to CSP rules) so it wouldn't "flash" (ie : you're in dark mode and normal mastodon theme in light mode) as tag can be changed as soon as possible, we don't need to wait for the tag to exist.document.querySelector('html').style.setProperty("background", backColor, "important");
However, that's not enough, as of right now, to avoid flash on Mastodon, one needs to override
<body>
background value, instantly. I need to be able to detect and fetch the body tag as soon as possible, because the tag need to exist, unlike<html>
.For both Chrome and Safari, MutationObserver is rarely fired outside of "Cmd+Ctrl+R" (command that clear the cache).
MutationObserver is really reliable to fetch any tag in the
<head>
, I don't understand why.I have a workaround which use requestAnimation frame to detect elements, but I can't manage to override fast enough to avoid the weird flash.
You can look at my code here : https://github.com/Write/TangerineUI-Userscript/blob/main/TangerineUI.user.js
I hope I'm just missing something and there's a better way or API.
Thanks a lot for reading me.
EDIT :
I just wanted to add that I have other userscripts for other website, with no CSP protection, and injecting my custom css (embedded inside the userscript itself, this time) with :
and it does the flashing too. Which mean it's not injecting the style fast enough, it does work great on firefox though.
Apparently Darkreader has a way around that since applying dark theme doesn't do any flashing. I really don't know what I'm missing here.
The text was updated successfully, but these errors were encountered: