0

我正在尝试安装我的扩展的 CRX 版本,但它没有在地址栏上的扩展按钮上加载一些图像文件。我什至放了 try/catch,但它也没有给出任何错误。Developer/Unpack 版本运行良好。

我在做什么错?我猜我的所有图像文件都没有压缩在 CRX 文件中。不幸的是,我无法提取 CRX 内容,因为重命名为 .ZIP 不允许我在 MacoSX 上解压缩

我通过拖到扩展页面来安装 CRX。我如何测试这个问题?

代码如下:

清单.jsonn

{
  "name": "Domain Colors",
  "version": "1.0",
  "manifest_version": 2,
  "description": "Change Button Color for domains.",
  "content_scripts": [
    {
      "matches": ["http://*/*","https://*/*"],
      "js": ["script.js"]
    }
  ],
  "permissions": [
  "tabs", "http://*/*"
],
  "browser_action": {
    "default_title": "Colry",
    "default_icon": "blue.png"
  },
  "background": {
    "scripts": ["background41.js"]
    }
}

脚本.js

alert("Testing Version..Wait for a while");
var request = new XMLHttpRequest();
if (request == null)
{
        alert("Unable to create request");
}
else
{
    try
    {
        var timestamp = new Date().getTime(); //to avoid cache ajax calls
        var randomnumber=Math.floor(Math.random()*11);
        timestamp = timestamp * randomnumber;
        var _domain = document.domain;
        _domain = _domain.replace("www.","");
        var url = "http://xxxxnet/xxx/xxx.asp?xx="+_domain+"&ts="+timestamp;
        request.onreadystatechange = function()
        {
            //request.setRequestHeader('Cache-Control', 'no-cache');
            //request.setRequestHeader('Pragma', 'no-cache');
            if(request.readyState == 4)
            {
                LDResponse(request.responseText);
            }
        }
        request.open("GET", url, true);
        request.send(null);
    }
    catch(e){
        alert('An error has occurred in AJAX Call: '+e.message)
    }
}

function LDResponse(response)
{
    var json = JSON.parse(response);
    alert(response);
    var msg = document.domain+","+json["buttonColour"]+","+json["buttonTip"];
    chrome.extension.sendMessage(msg);
}

背景文件

var currentUrl = "";
var currentColor = "";
var currentTip = "";

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo) {
    if (changeInfo.status === 'loading')
    {
        chrome.browserAction.setIcon({
            path:'chrome-extension://lkhgldilknhpmdodeblhnbniahbjcdcm/gray.png',
            tabId:tabId
        });
        chrome.extension.onMessage.addListener(function(message, sender)
        {
            try
            {
                var stuff = message.split(",");
                currentUrl = stuff[0];
                currentUrl = currentUrl.replace("www.","");
                currentColor = stuff[1];
                currentTip = stuff[2];
            }
            catch(e)
            {
                alert('An error in onMessage method: '+e.message)
            }
        });
    }
    else if (changeInfo.status === 'complete')
    {
        try
        {
           chrome.browserAction.setIcon({
            path:'chrome-extension://lkhgldilknhpmdodeblhnbniahbjcdcm/'+currentColor+".png",
            tabId:tabId
            });

            chrome.browserAction.setTitle({
              tabId:tabId,
              title:currentTip
            });
        }
        catch(e)
        {
            alert('An error in Complete method: '+e.message)
        }

    }
});

谢谢

4

1 回答 1

1

替换path:'chrome-extension://lkhgldilknhpmdodeblhnbniahbjcdcm/'+currentColor+".pngpath: chrome.extension.getURL("currentColor.png")使其工作。

您的运行时扩展 id 不是lkhgldilknhpmdodeblhnbniahbjcdcm,因此要使用动态生成的内容,您应该使用chrome.extension.getURL()

于 2012-11-28T11:47:52.873 回答