回答

3

如果沒有content scripts,您不能這樣做,但您可以通過使用activeTabchrome.tabs.executeScript以最小權限執行此操作。這將是這個樣子:

manifest.json的

"permissions": [ 
    "activeTab","contextMenus" 
], 
"background": { 
    "scripts": ["background.js"] 
} 

background.js

chrome.contextMenus.onClicked.addListener(function(info, tab) { 
    chrome.tabs.executeScript(tab.id, 
    {code:"function getCharset(){return document.charset;}getCharset();"}, 
    function(results){ 
     // results[0] will now contain the charset for the page in question 
    }); 
}); 
相關問題