我用这个后台脚本为 Google Chrome 创建了一个扩展background.js
:
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(tab.id, {code:"document.body.style.background='red !important';"}); // doesn't work
chrome.tabs.executeScript(tab.id, {code:"alert('hello');"}); // runs alert
});
我想document.body.style.background='red !important';
在网页的上下文中运行。
我该怎么做?
manifest.json
:
{
"name": "Test",
"version": "1.0",
"manifest_version": 2,
"description": "Test",
"browser_action": { "default_icon": "icon.png" },
"background": { "scripts": ["background.js"] },
"permissions": ["tabs", "*://*/*"]
}