Need help with using the new insertCSS and removeCSS in manifest v3. The documentation is not very clear and lacks examples.
I have a CSS file that I need to inject into a page and then remove it.
The code looks something like this:
background.js
document.getElementById('chat').addEventListener('change', (e) => {
var chat = e.path[0].value;
// inject css file
let css = document.createElement('link');
css.rel = 'stylesheet';
css.type = 'text/css';
css.href = 'css/chat-rtl.css';
if (chat == 'rtl') {
chrome.scripting.insertCSS({ injection: { css } });
console.log('rtl');
} else {
chrome.scripting.removeCSS({ injection: { css } });
console.log('ltr');
}
});
Error Log:
Uncaught TypeError: Error in invocation of scripting.removeCSS(scripting.CSSInjection injection, optional function callback): Error at parameter 'injection': Unexpected property: 'injection'. at HTMLSelectElement. (background.js:10:22)