0

的問題很簡單:如果讓Chrome擴展程序,並使用page_action不開發模式下工作

chrome.pageAction 

把圖標的地址欄裏面,這在擴展不DEVELOPMODE工作。爲什麼不 ?

background.html

<script language="javascript"> 

chrome.pageAction.onClicked.addListener(function (tab) { 
    chrome.tabs.executeScript(tab.id, { 
     file: "jquery.js" 
    }, function() { 
     chrome.tabs.executeScript(tab.id, { 
      code: '$[CODE JQUERY];' 
     }); 
    }); 
}); 

chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { 
    if(tab.url.indexOf("facebook.com") != -1) { 
     chrome.pageAction.show(tabId); 
    } 
}); 

</script> 
+1

你在哪裏調用這個API?請注意,您不允許在內容腳本中使用它。 –

+0

我在background.html – xkill

+0

中使用它您需要顯示背景腳本的代碼。也請調試後臺頁面並檢查錯誤。 –

回答

1

特約康拉德Dzwinel評論,你不能在你的HTML中使用內嵌代碼。將其移至外部JavaScript,然後重試。

順便說一下,Page Actions在開發模式下工作,我一直都在使用它們!以下是我的Background.js中的一個示例,用於檢查更新的選項卡上的頁面URL;如果URL是我正在尋找的,我將顯示Page Action。

/** 
* Listener for Displaying the Extension Page Action when the Tab is updated. 
* @private 
* @event displayPageAction 
* @param {Number} tabId The tabId given by the tabs listener to know which tab was updated. 
* @param {Object} changeInfo The current status of the tab. 
* @param {Object} tab The metadata of the tab. 
**/ 
var displayPageAction = function (tabId, changeInfo, tab) { 
var regexAIESEC = new RegExp(/http:\/\/www.myaiesec.net\//); // My page URL 
var match = regexAIESEC.exec(tab.url); 
// We only display the Page Action if we are inside a MyAIESEC Page AND it finished loading. 
if(match && changeInfo.status == 'complete') { 
    chrome.pageAction.show(tab.id);  
} 
}; 

您通過選項卡onUpdated even handler來回調此代碼。

chrome.tabs.onUpdated.addListener(displayPageAction); 
相關問題