出现在地址栏之外的 Chrome 扩展页面操作 [英] Chrome extension page action appearing outside of address bar

查看:25
本文介绍了出现在地址栏之外的 Chrome 扩展页面操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个 Chrome 扩展页面操作,实现如下:

I wrote a Chrome Extension page action, with the following implementation:

在 manifest.json 中:

In manifest.json:

  "permissions" : [
    "declarativeContent"
  ],

在 background.js 中:

In background.js:

chrome.runtime.onInstalled.addListener(function() {
  // Replace all rules ...
  chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
    // With a new rule ...
    chrome.declarativeContent.onPageChanged.addRules([
      {
        conditions: [
          new chrome.declarativeContent.PageStateMatcher({
            pageUrl: { urlMatches: 'www.somewebsite.com/(translate|revise)/' },
          })
        ],
        // And shows the extension's page action.
        actions: [ new chrome.declarativeContent.ShowPageAction() ]
      }
    ]);
  });
});

我注意到在大多数 Chrome 浏览器中,页面操作图标在地址内正确显示,并且仅在遇到匹配页面时才会出现:

I noticed that in most Chrome browsers, the page action icon appears correctly inside the address and only appears when the matching page is met:

但是,在某些浏览器中,最近页面操作开始显示为启用/禁用的浏览器操作,即在地址栏之外,这非常笨拙,因为围绕页面操作图标的整个想法是当且仅当页面是与他们相关.大多数情况下显示禁用的页面操作没有意义.事实上,它发生在几天前它曾经运行良好的浏览器上,就像 Chrome 更新有一些副作用一样.

However, in some browsers recently page actions started appearing as enabled/disabled browser actions, i.e. outside the address bar, which is a lot clumsier because the whole idea around page actions icons is that they appear if and only if the page is relevant to them. There is no point showing a disabled page action for most of the time. Actually, it happened to browsers where it used to work well days ago, like if a Chrome update had some side effects.

我认为这与某些 Chrome 设置有关,该设置现在显示所有扩展程序,但有什么方法可以强制页面操作在地址栏中一致显示,并且仅在它真正有用时才显示?

I presume this is related to some Chrome setting that now shows all extensions there, but is there any way I can force the page action to appear consistently in the address bar and only appear when it can be really useful?

推荐答案

这似乎是 Chrome 新更新的结果,开发人员可能认为大多数用户不会知道他们安装了其他扩展程序.

It appears like this is the result of a new update to Chrome, with the developers probably reasoning that most users would not know that they had extensions installed otherwise.

公告链接:https://groups.google.com/a/chromium.org/forum/#!searchin/chromium-extensions/upcoming/chromium-extensions/7As9MKhav5E/dNiZDoSCCQAJ

看起来扩展程序开发人员对此无能为力,但我真的希望 Google 恢复此更改.

It doesn't look like extension developers can do anything about this, but I really hope Google reverts this change.

这篇关于出现在地址栏之外的 Chrome 扩展页面操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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