How does stylus insert css after the original css but before the page is rendered? #1179
-
Hi there. but the stylus extension overwrites the original style and applies the custom style as soon as the page is rendered. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
If your extension simply inserts a CSS file that resides in your extension, you only need "content_scripts": [{
"matches": ["https://www.example.com/*"],
"css": ["style.css"],
"run_at": "document_start"
}] Then just make sure that your selectors override the site's selectors, see tutorials on CSS specificity and use |
Beta Was this translation helpful? Give feedback.
-
Hmm indeed Chrome doesn't put the In that case you'll have to add a DOM element in a js content script that runs at document_start and then move it after the
const style = document.createElement('style');
style.textContent = `
body { color: red }
`;
document.documentElement.appendChild(style);
new MutationObserver((mutations, observer) => {
if (document.body) {
observer.disconnect();
document.documentElement.appendChild(style); // move the style
}
}).observe(document.documentElement, {childList: true}); An alternative solution would be to use chrome.tabs.insertCSS inside chrome.webNavigation.onCommitted listener and specify |
Beta Was this translation helpful? Give feedback.
Hmm indeed Chrome doesn't put the
css
declared in manifest.json at the end of style list. Oh well, yet another bug/deficiency that won't be fixed in this century if ever.In that case you'll have to add a DOM element in a js content script that runs at document_start and then move it after the
body
element: