假设您对所有功能都有浏览器操作,您可以使用chrome.webRequest.onHeadersReceived、chrome.browserAction.enable()和chrome.browserAction.disable()检测和启用\禁用扩展
伪代码
清单.json
{
"name": "Detect Mime type",
"version": "1.0",
"description": "Detecting Mime type and enabling browser action",
"permissions": ["webRequest", "webRequestBlocking",
"<all_urls>"],
"background": {
"scripts": ["background.js"]
},
"browser_action":{
"default_popup":"popup.html", // Use you related code here
"default_icon":"icon.jpg"
},
"manifest_version": 2
}
背景.js
chrome.webRequest.onHeadersReceived.addListener(function (object){
// Do your code for related header(s)
//Invoke chrome.browserAction.enable(integer tabId) or chrome.browserAction.disable(integer tabId)
},{urls: ["<all_urls>"]});
chrome.tabs.query({"status":"complete"}, function(tabs){
//Disable all browser actions using chrome.browserAction.disable(integer tabId)
});
如果您需要更多信息,请与我们联系。