Skip to content

Instantly share code, notes, and snippets.

@royling
Last active November 13, 2024 15:15
Show Gist options
  • Save royling/eb5276577f53d1332e413311ca904df8 to your computer and use it in GitHub Desktop.
Save royling/eb5276577f53d1332e413311ca904df8 to your computer and use it in GitHub Desktop.
Click Chrome extension icon to execute scripts on active tab
chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: {
tabId: tab.id,
},
files: ["content.js"],
});
});
// modify page content here...
{
"manifest_version": 3,
"name": "Foo",
"version": "0.1",
"description": "Blabla...",
"action": {
"default_icon": {
"16": "images/icon16.png",
"32": "images/icon32.png"
},
"default_title": "Foo"
},
"permissions": ["activeTab", "scripting", "tabs"],
"host_permissions": [
"*://*/*"
],
"background": {
"service_worker": "background.js"
}
}
@CarterSarkela
Copy link

Important note for anyone like me who tries this in the future: make sure that your background.js folder is in the same file as your manifest, otherwise the manifest is unable to access it. In general have all files in the same file as the manifest. Thanks for the code though, saved our lives at this hackathon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment