瀏覽器在頁面上執行 executeScript 的操作
manifest.json
{
"name": "Hello Page",
"description": "Add 'Hello' to the current page.",
"version": "1.0",
"permissions": [
"activeTab"
],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"browser_action": {
"default_title": "Say Hello on this page"
},
"manifest_version": 2
}
background.js
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript({
code: 'document.body.insertAdjacentText("beforeBegin", "Hello!")'
});
});