边缘:当使用具有多种尺寸的默认图标时,browserAction.setIcon不起作用 [英] Edge: browserAction.setIcon not working when using a default icon with multiple sizes

查看:129
本文介绍了边缘:当使用具有多种尺寸的默认图标时,browserAction.setIcon不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

manifest.json指定多种尺寸的默认图标时,我无法在Microsoft Edge中使用browser.browserAction.setIcon:

I can't get browser.browserAction.setIcon to work in Microsoft Edge when manifest.json is specifying a default icon in multiple sizes:

manifest.json

manifest.json

{
  "manifest_version": 2,
  "name": "test",
  "version": "0.0.1",
  "author": "John Doe",
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "browser_action": {
    "default_icon": {
      "19": "icon.png",
      "38": "icon2.png"
    }
  }
}

background.js

background.js

setInterval(function() {
  browser.browserAction.setIcon({
      path: "testimage.png"
  });
}, 2000);

未记录任何错误,代码已执行,但图标未更改.相同的代码在Chrome中可以正常工作.

No error logged, the code is executed but the icon doesn't change. The same code works fine in Chrome.

将manifest.json更改为

Changing the manifest.json to

"browser_action": {
  "default_icon": "icon.png"
}

解决了该问题,但是如果我需要使用多个默认图标怎么办?

Fixes the issue, but what if I need to use multiple default icons?

不幸的是,即使"default_icon": "icon.png"都不可用,即使Edge高兴地加载了扩展名,在将其提交到商店时,验证也失败了

Unfortunately not even "default_icon": "icon.png" is usable, even though Edge happily loads the extension, when submitting it to the store, the validation fails with

验证失败:无效的类型:字符串(预期的对象) 架构位置:/properties/browser_action/allOf/0/properties/default_icon/type 清单位置:/browser_action/default_icon 扩展清单的验证失败:Extension \ manifest.json

Validation failed: Invalid type: string (expected object) Schema location: /properties/browser_action/allOf/0/properties/default_icon/type Manifest location: /browser_action/default_icon Validation failed for extension manifest: Extension\manifest.json

MDN确实是这样说的: https://developer.mozilla.org/zh-CN/Add-ons/WebExtensions/manifest.json/browser_action#Browser_compatibility

Which is indeed what MDN says: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/browser_action#Browser_compatibility

"default_icon"必须是具有明确大小的对象.

'default_icon' must be an object, with explicit sizes.

推荐答案

最后,我得出的结论是Edge不喜欢manifest.jsonbrowserAction.setIcon,它会静默失败,不会产生任何错误.

In the end I came to the conclusion that Edge doesn't like string values for the browser action icon path, neither in manifest.json nor in browserAction.setIcon, it fails silently without producing any error.

一种有效的方法是始终在manifest.json和每个browserAction.setIcon调用中都设置显式大小,即使不同大小都指向同一张图像.

A way to make it work is to always set explicit sizes in both manifest.json and in every browserAction.setIcon call, even if the different sizes all point to the same image.

manifest.json

manifest.json

{
  "manifest_version": 2,
  "name": "test",
  "version": "0.0.1",
  "author": "John Doe",
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "browser_action": {
    "default_icon": {
      "19": "icon.png",
      "38": "icon2.png"
    }
  }
}

background.js

background.js

browser.browserAction.setIcon({
    path: {
      "19": "testimage.png",
      "38": "testimage.png"
});

这篇关于边缘:当使用具有多种尺寸的默认图标时,browserAction.setIcon不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆