回答

0

請按照此處定義的方式嘗試此操作。

的manifest.json

{ 
    "manifest_version": 2, 
    "name": "Execute script app", 
    "version": "1.0", 
    "background": { 
     "persistent":true, 
     "page":"background.html" 
    }, 
    "content_scripts": [{ 
      "matches": ["http://*/*"], 
      "js": ["app.js"] 
     } 
    ], 
    "permissions": [ 
     "tabs", 
     "http://*/*" 
    ] 
} 

background.html

<script src="background.js"></script> 

background.js

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab){ 
    if(changeInfo && changeInfo.status == "complete"){ 
     chrome.tabs.executeScript(tabId, {code: "alert('Page loaded.');"}); 
    } 
}); 

app.js

//well this is just empty since ur not doing anything here