Migrated manifestV2 to V3 after that chrome.action.onClicked.addListener not working

Viewed 50

While migrating from manifest v2 to v3 facing issue(chrome.action.onClicked.addListener not working/invoking).

I have a manifest.json defined like this

{ 
"name": "dummy",
"manifest_version": 3,
"version": "5.2.0",
"version_name": "5.2.0",
"description": "The dummy v5.2.0  plugin allows our users to gain instant access to 
their metadata and data.",
"action": {
 "default_title": "execute.js will run (watch the Chrome DevTools' console)"
},
"content_scripts": [
 {
  "js": ["content.js"],
  "matches": [
    "https://*/*",
    "http://*/*"
  ]
}
 ],
"background": {
  "service_worker": "background.js"
},
"permissions": [
  "contextMenus",
  "tabs",
  "scripting",
  "storage"
],
"host_permissions": [
  "https://*/*",
  "http://*/*"
],
"web_accessible_resources": [{
   "resources": ["*.html"],
   "matches": ["https://*/*","http://*/*"]}]}
  

and background.js file has this code

chrome.action.onClicked.addListener(function (tab) {
     chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
    setDomain({ tab: tabs[0] });
 });});

I'm really lost here and it's extremely hard to debug.This code was working before migrating to manifest v3.

1 Answers

(I will edit this answer once the OP has given us more information)

I have created a test extension with

  • your manifest.json
  • your background.js, with setDomain({ tab: tabs[0] }); replaced with console.log("setDomain({ tab: tabs[0] });");
  • a content.js that only contains the code console.log("content.js");

When I click the action in my test extension, it excutes the code console.log("setDomain({ tab: tabs[0] });");

In other words: The code you have shown us is not enough to diagnose your problem.

We can only help you if you do the following:

Please upload your extension's entire source code to Github or a similar website.

If you don't want to upload your extension's entire source code:

Please create a simplified version of your extension that reproducibly demonstrates your problem. Then upload the simplified extension's entire source code to Github or a similar website.

Related