在特定网址上显示页面动作图标 [英] Display Page Action Icon on specific url

查看:70
本文介绍了在特定网址上显示页面动作图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的网页操作图标显示在特定的网址上。我尝试过实现这里,但这些需要trunk / dev版本。

I'm trying to get my page action icon to show on a specific url. I've tried implementing the examples here but these require the trunk/dev release.

现在的代码取自a SO answer 。但是这似乎不起作用,因为tab对象在我的测试中从来没有url属性可以限制。

The current code I have is taken from a SO answer. But this doesn't seem to work because the tab object never has a url property in my testing to be able to restrict on.

// background.js

// background.js

function checkURL(tabId, info, tab) {
    if (info.status === "complete") {
        if (tab.url) {
            // restrict here
            chrome.pageAction.show(tabId);
        }
    }
}
chrome.tabs.onUpdated.addListener(checkURL);

//清单

{
    "manifest_version": 2,

    "name": "My first extension",
    "version": "1.0",

    "content_scripts": [
        {
            "matches": ["http://www.google.com/*"],
            "js": [
                "script.js"
            ],
            "run_at": "document_idle"
        }
    ],

    "background": {
       "page": "background.html",
       "persistent": false
    },

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

我做错了什么?

What am I doing wrong?

推荐答案

这适用于我:

This works for me:

//background.js
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
  if (~tab.url.indexOf('.pl')) {
    chrome.pageAction.show(tabId);
  }
});

//manifest.json
"permissions": [
"tabs"
]

而我没有使用 persistent:false

这篇关于在特定网址上显示页面动作图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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