-
-
Notifications
You must be signed in to change notification settings - Fork 365
Closed
Closed
Copy link
Description
Feature Request
After 2 hours of debugging, I've figured out that for an unlisted script to be injectable into the page it has to be declared in the manifest, like so:
// See https://wxt.dev/api/config.html
export default defineConfig({
manifest: {
web_accessible_resources: [
{ resources: ["page.js"], matches: ["<all_urls>"] }
]
}
});
it would be good to mention this in the unlisted scripts docs or add it there automatically.
Is your feature request related to a bug?
N/A
What are the alternatives?
N/A
Additional context
This is my setup:
// page.ts
export default defineUnlistedScript(() => {
console.log('unlisted script!')
})
// content.ts
export default defineContentScript({
matches: ['<all_urls>'],
main() {
let pageScriptElem: HTMLScriptElement | null = null;
browser.runtime.onMessage.addListener(
async function (request, sender, sendResponse) {
if (request.cmd && request.cmd === 'process') {
if (pageScriptElem !== null) pageScriptElem.remove();
pageScriptElem = document.createElement("script")
pageScriptElem.src = browser.runtime.getURL("/page.js")
pageScriptElem.type = 'text/javascript'
document.head.appendChild(pageScriptElem)
}
}
);
}
});
Let me know if i'm misunderstanding how one should inject scripts like these
Metadata
Metadata
Assignees
Labels
No labels