does hmr also work for all 3 types of content script? (declared statically, declared dynamically, and programmatically injected) #24
Unanswered
devhandler
asked this question in
Q&A
Replies: 1 comment
-
Hello, yes it looks like all 3 types of content scripts work correctly with HMR: You can see an example in content_scripts branch. output.mp4import injectProgrammatically from "../content/inject-programmatically?script";
import injectWithDynamicDeclarations from "../content/inject-with-dynamic-declarations?script";
// Inject programmatically
// https://developer.chrome.com/docs/extensions/mv3/content_scripts/#programmatic
chrome.action.onClicked.addListener((tab) => {
if (tab.id) {
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: [injectProgrammatically],
});
}
});
// Inject with dynamic declarations
// https://developer.chrome.com/docs/extensions/mv3/content_scripts/#dynamic-declarative
chrome.scripting
.registerContentScripts([
{
id: "session-script",
js: [injectWithDynamicDeclarations],
persistAcrossSessions: false,
matches: ["https://*/*"],
runAt: "document_start",
},
])
.then(() => console.log("registration complete"))
.catch((err) => console.warn("unexpected error", err));` |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
sometimes we have to use dynamic or progammatic injection for content script. does this lib also support these 2 types of content script?
Beta Was this translation helpful? Give feedback.
All reactions