-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Selma: Content script sometimes gets injected after DOMContentLoaded event on OperaGX #158
base: main
Are you sure you want to change the base?
Selma: Content script sometimes gets injected after DOMContentLoaded event on OperaGX #158
Conversation
Seems like a fix, but there is some strange weirdness in this file. First of all: why is the Css injected via js? This could also be declared in the manifest.json, couldn't it? Also, the reason this happens is, that we try to inject before the page is loaded and sometime it already is once the code is run. Correct? |
Because the goal was to give the user the chance to disable the stylesheet, as it only works with the changes the JS script makes to the page
The initial goal was to prevent a flickering effect when the style sheet gets applied after the page is loaded, but with the current solution it does get applied after the page is loaded so I am not sure what I wrote there 😅 |
This is probably nitpicking, but wouldn't be the better way to do this to inject the Css, prefix all styles in the Css with a specific class and or remove the class to the body? I just think injecting files is way less safe and more prone to being blocked in the future 😅
Why isn't the reading of the setting and the css injection (based on the result) done while waiting for the event? Because these operations should be working even without the fully loaded Dom, shouldn't it? |
Yes changing a flag class on the root would be a better solution, I did not think of that back then but if I find the time for it I will change it.
Yes they could be done in parallel, I think in reality this does not really change anything. Weirdly this entire issue is not present on firefox, but can also be observed on safari |
Ok so I just tested it with |
It still looks like injectCSS() get only called after DOMContentLoaded. We should probably think about this as two separate actions: applying styles and applying DOM changes. So probably you could do something like this: //...
// Inject CSS
storage.get(['improveSelma'], result => {
if(!result.improveSelma) return;
injectCSS('base');
//... Inject the other styles based on path
});
// Running this outside the async makes it way more predicable
if (document.state !== 'loading') main();
else appendListener('DOMContentLoaded', main);
async main() {
const enabled = await new Promise(resolve => storage.get(['improveSelma', r => resolve(r.improveSelma));
if (!enabled) return;
addCreditsBanner();
applyChanges();
//...
}
//... All the other definitions This would fix two things:
|
Injecting the CSS before the DOMContentLoaded unfortunately is not possible, because that way the CSS styles will get overridden by the CSS styles from selma :/ |
Even when using |
Yes, for some reason the alternating colors in the table get messed up, it's all a bit strange. Maybe I did something wrong though, I am not really a web dev expert to be honest |
Pull Request
Description
This resolves an issue where the Selma improvement script won't activate when it gets injected after the
DOMContentLoaded
event. It also resolves a small layout issue with the credit banner.See: https://stackoverflow.com/a/39993724
Type of change
Further info
Testing
We have 1500+ Users. Please test your changes thoroughly.
npm run test
locally