chrome.action is undefined migrating to v3 manifest
Asked Answered
Y

1

3

I'm trying to mirate an extension from v2 to the v3 manifest.

My goal is by clicking on the extension icon, the option page will open.

Now I checked the migration guide .

So the v2 (is working) is using chrome.browserAction.onClicked.addListener. And the guide tells me to use chrome.action.onClicked.addListener in v3

So I made a manifest:

{
  "manifest_version": 3,
  "version": "0.0.3",
  "name": "Live_option_page",
  "description": "build live option page with Vuetify 3",
  "minimum_chrome_version": 93,
  "icons": {
    "16": "images/16x16.png"
  },
  "action": {
    "default_icon": "images/16x16.png"
  },
  "background": {
    "service_worker": "background/index.js"
  },
  "web_accessible_resources": [{
    "resources": ["/options/*"],
    "matches": ["<all_urls>"]
  }],
  "options_ui": {
    "page": "options/index.html",
    "open_in_tab": true
  },
  "permissions": [
    "activeTab",
    "tabs",
    "browser_action"
  ]
}

Now I have a service_worker /background/index.js

const API = chrome || browser;

console.log(API.action) // => will print undefined

API.action.onClicked.addListener((tab) => {
    console.log("clicked icon on tab ", tab);
    API.tabs.create({url: "options/index.html"});
})

So the Service Worker crashed, and chrome.action is undefined.

Yardarm answered 3/12, 2021 at 15:10 Comment(6)
Check the minimal example, because there are two errors in the manifest (min version should be string, browser_action is not a permission). Besides that it works, so not able to reproduce/answer actual question and perhaps some code is missing. Side note: do you use the browser action for other things? If no, it would be possible to configure popup behavior in the manifest (again not related to actual cause of the problem, but a solution).Sylph
@Sylph thanks I now also got the error minimum_chrome_version invalid value. I didn't got it before. If you want you can submit it as the answer. Thanks for the permissions, I was just checking some things found on the internet.Yardarm
@JohanHoeksma I happened to hit the same issue. Was any solution to the problem?Skyway
I think "minimum_chrome_version": 93, was not validYardarm
Any of you got it solved? I have no manifest errors but chrome.action is nowhere to be find even though I am using manifest v3 and I am trying to use it in the background.Kandi
Removing the extension and loading it again fixed it for me. A few hours wasted...Kandi
M
0

Try setting changing the action key in your manifest to an empty object:

{
...
"action": ""
}

The rest of your code seems fine.

Metaplasia answered 4/8, 2022 at 8:45 Comment(1)
For me this caused error. An alternative would be to set action to and empty object {}Nominee

© 2022 - 2024 — McMap. All rights reserved.