Chrome内容脚本未加载JS

时间:2012-05-01 19:38:25

标签: google-chrome-extension content-script

我正在尝试使用Chrome浏览器扩展程序,它可以在上下文菜单中执行有趣的操作。问题是,我无法在manifest.json content_scripts中加载JS文件。

我没有收到错误,文件根本就没有加载。

脚本很好,如果我把它们放在我的后台页面中,它们会通过该背景页面点亮。其缺点是仅限于背景页面。

{
"name": "Mini",
"description": "Mini",      
"permissions": ["contextMenus","management","contentSettings","tabs","http://*/*","https://*/*","editable"],
"version": "0.1",
"manifest_version": 1,
"background_page": "mini.html",
"icons" : {"16" : "mini.png"},
"contexts" : ["link","tab","page"],
"content_scripts": [{"matches":["<all_urls>"],"js":["jquery172min.js","mini.js"]}]
}

我尝试过各种形式的比赛,包括"http://\*/\*", "https://\*/\*", "\*://\*/\*"

我尝试过空白,没有空白。我在这里画一个空白。

任何帮助都将不胜感激。

$(document).ready(function () {

alert("page is ready");
},true);    

我为此道歉。这是我用来测试扩展程序是否已加载的javascript / Jquery的副本。这只是一个简单的警报。

1 个答案:

答案 0 :(得分:2)

Content scripts无法使用chrome.contextMenus API(事实上,这些只能使用some of the chrome.extension methods)。

可以通过match patternschrome.contextMenus.create({title: 'Test', documentUrlPatterns: 'http://*/*'});应用于各个菜单项 创建的菜单项也可以修改(chrome.contextMenus.update)并删除(chrome.contextMenus.remove)。

要在内容脚本和背景页面之间进行通信,请参阅Message passing