2012-11-28 96 views
0

我正在嘗試安裝擴展程序的CRX版本,但它沒有在地址欄上放置一些擴展按鈕上的圖像文件。我甚至放了try/catch,但它沒有給出錯誤也是。開發者/解包版本工作得很好。Chrome擴展程序:CRX文件無法正常工作

我在做什麼?我猜想我所有的圖像文件都沒有壓縮在CRX文件中。不幸的是,我無法提取CRX內容,因爲重命名爲.ZIP不讓我在MacoSX上解壓縮。

我正在通過拖放到擴展頁面來安裝CRX。 如何測試該問題?

代碼給出如下:

Manifest.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"] 
    } 
} 

的script.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) 
     } 

    } 
}); 

感謝

+1

分享您的代碼?你使用chrome.extension.getURL()嗎? – Sudarshan

+0

@Sudarshan代碼在原始帖子中添加。它成功地進行HTTP調用。這只是不加載綠色/ red.png圖像 – Volatil3

回答

1

更換path:'chrome-extension://lkhgldilknhpmdodeblhnbniahbjcdcm/'+currentColor+".pngpath: chrome.extension.getURL("currentColor.png")才能正常工作。

你的運行中分機標識不lkhgldilknhpmdodeblhnbniahbjcdcm,所以要使用動態生成的內容,你應該使用chrome.extension.getURL()

+1

愛它! Thans Bro。它在我的最後工作。我正在發送給客戶以瞭解他的反饋。我接受了它,因爲我認爲這是問題所在。 – Volatil3

+1

@ Volatil3:也替換'gray.png'的所有事件 – Sudarshan

相關問題