hey . I need change this part of my manifest via java script codes inside popup script (dynamicaly)
“content_scripts”: [
{
“matches”: ["://.mozilla.org/*"],
“js”: [“test.js”]
}
]
is there any way?
hey . I need change this part of my manifest via java script codes inside popup script (dynamicaly)
“content_scripts”: [
{
“matches”: ["://.mozilla.org/*"],
“js”: [“test.js”]
}
]
is there any way?
There is a special API for Firefox only:
thanks for answer . i found a cod there . but it not working can you check i wrote it correct please
var registered = null;
registered = await browser.contentScripts.register({
matches: "*://*.mozilla.org/*",
js: ["test.js"],
runAt: "document_idle"
});
i want use this inside popup script to execute background script to that domain for permanent time . do it remain after page refresh?
I think your matches
string is wrong, you are missing a star before the first dot, see the docs for some examples:
Also, some mozilla domains are protected and can’t run content scripts, like the addons store or support page.
And lastly, yes, if you register a content script, it will be loaded on the domain all the time (well, till the browser restart I think).
PS: to paste a code here, place triple backticks (```) on the line before and after the code.
thanks for tip.This is another modification i paste from another place. i checked any thing that i know(i have low knowledge) but not working yet . i know your answer is the solustion
const registered = await browser.contentScripts.register({
matches: ["*://*.com/*"],
js: [{file:"/test.js"}],
"allFrames": true,
runAt: "document_start"
});
when i say it’s not working i mean popup script crash and stop working
Best Regards
after i removed ( await
) popup script executed but my test.js not executed
That match pattern looks still bad. Why not try something simple, something from the example page I’ve posted?
Also, if the registering fails, you should see some error in the console - open the background script console for example from the "about:debugging#/runtime/this-firefox"
page - click there the “Inspect” button.
thanks problem fixed . if use this method inside popup content as soon as you close it script will unregister too . must use it on background script and register another script.
i had 2 mistake on this . one must use await inside async function
two: some mistake in note
async function registerScript( )
{
await browser.contentScripts.register({
matches: ["*://*.org/*"],
js: [{file:"test.js"}],
allFrames: true,
runAt: "document_idle"
});
}