I would like to ask if there is any way to inject css to any page from the background of my extension to create a button on each page, if someone could help me
Hello @dmillergg
not sure if i get the whole picture but you can use js and apply any css and even add html element or anything you like
hope that help and have a nice day
Let me explain myself better, I have knowledge that it can be done, only when I do it, it tells me the following error: Error: Missing host permission for the tab and in the manifest of my extension I have the permission of activetab so I don’t know what else to do, this is my code:
const css = .mkbtn{ background-color:rgba(0, 0, 255, 0.61); font: bold; font-weight: bolder; width: 5em; border-radius: 5em; border: none; height: 3em; right: 0; top: 0; margin-top: 1em; margin-right: 1em; position: fixed; box-shadow: 5px 5px 10px rgba(0,0,0,0.7); } .mkbtn:hover{ background-color:rgb(108, 193, 247); }
;
function button() {
const getStorage = browser.storage.local.get();
getStorage.then(async (item) => {
if (item.kiosk_mode) {
removeButton();
browser.tabs.insertCSS({ code: css });
let button = document.createElement(“button”);
button.className = “mkbtn”;
button.innerText = “Next”;
document.body.appendChild(button);
}
});
}
Anyway thank you very much
to make sure i got it right
this code is part of extension you develop ?
if yes then i the best one to ruin your code as i have 0 experience on that part
i know it silly suggestion but check this link https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions
i will ask @chrisdavidmills if he can help you on that one
hope you fix the issue and have a nice day for both of you
ok thank you very much anything you find please tell me
you very welcome
Hey bud, its difficult without seeing the whole script, but reading through your function. I think I have a better image in my head,
I think you are using the localStorage API all wrong.
MDN-window.localStorage
and *now im no expert on this, but your async function is not awaiting anything. I think you may need to re-check that bud.
Then again I could be wrong,
you are more than welcome to come and join our Discord Server, where we have other brillaint MDN’ers all studying and having fun
ok thanks i will check it again but i think its ok, anyway i check, thanks for the help anything write me
Hi @dmillergg! Have you asked for help about this in the add-ons discourse forum? I would love to help you, but I don’t know very much about add-ons/browser extensions.
Another option is look around MDN for some docs that might help. For example, https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Working_with_the_Tabs_API ?
All the best.