2017-09-01 79 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" 
    ], 
} 
相关问题