Answer the question
In order to leave comments, you need to log in
How to add CSS styles from a file in a browser extension to a website?
The extension may have a different address. It can either be connected as unpacked or from the store. So inserting a style element with a link will fail.
Just send the text and drive it into innerHTML - such a solution. Is there a prettier option?
Answer the question
In order to leave comments, you need to log in
It can either be connected as unpacked or from the store.
chrome.runtime.getURL('style.css')
. The path is specified from the root of the extension directory. injectCSSToPage (codeOrUrl, inline = true) {
if (inline) {
const style = document.createElement('style');
style.textContent = codeOrUrl;
document.head.appendChild(style);
} else {
const link = document.createElement('link');
link.href = codeOrUrl;
link.rel = 'stylesheet';
document.head.appendChild(link);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question