2017-09-01 103 views
0

我正在做一個簡單的擴展,我試圖在這些特定的網頁中包含一個內容腳本。但問題是他們沒有被納入網站。我使用Chrome的開發人員工具工具進行了檢查。 然後我將match_urls設置爲所有頁面,但仍不包含它們。Chrome擴展的內容腳本沒有被注入任何網頁

這裏的manifest.json的

{ 
    "manifest_version": 2, 

    "name": "TestExten", 
    "description": "Test description.", 
    "version": "1.0", 
    "browser_action": { 
    "default_icon": "icon.png", 
    "default_popup": "popup.html" 
    }, 
    "content_scripts": [ 
    { 
     "matches": ["http://*/*", "https://*/*"], 
     "run_at": "document.end", 
     "js": ["content.js"] 
    } 
    ], 
    "permissions": [ 
    "tabs", 
    "http://*/", "https://*/", 
    "cookies" 
    ], 
} 

content.js

alert("loaded"); 
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { 
    alert("received message"); 
}); 

什麼錯嗎?

+0

您確定擴展程序正在安裝並啓用嗎? – Barmar

+3

它是'document_end'(而不是'document.end') – Deliaz

回答

1

看一看這裏:https://developer.chrome.com/extensions/content_scripts

參數run_at接受document_end,不document.end。因此,您的清單看起來應該如下所示:

{ 
    "manifest_version": 2, 

    "name": "TestExten", 
    "description": "Test description.", 
    "version": "1.0", 
    "browser_action": { 
    "default_icon": "icon.png", 
    "default_popup": "popup.html" 
    }, 
    "content_scripts": [ 
    { 
     "matches": ["http://*/*", "https://*/*"], 
     "run_at": "document_end", 
     "js": ["content.js"] 
    } 
    ], 
    "permissions": [ 
    "tabs", 
    "http://*/", "https://*/", 
    "cookies" 
    ], 
} 
相關問題