我正在尝试稍微了解一下google-extensions,所以我尝试制作一个简单的扩展程序,使用api
向ajax
发出请求,然后返回一些结果。
当我直接在浏览器(localhost)中测试时,它运行正常,但是当我尝试将其添加到chrome://extensions/
并在开发者模式下单击加载解压扩展... 时,它不起作用。
这是我的app.js
ajax
来电:
document.addEventListener('DOMContentLoaded', function() {
$( '#form-custom' ).on( 'submit', function( event ) {
event.preventDefault();
user = $('#user').val();
$.ajax({
url:'https://sitewiththeapi.net/api/searchuser/'+user+'/show/list.json',
dataType:'jsonp'
})
.done(function(data){
console.log(data);
})
.fail( function(jqXHR, textStatus, errorThrown){
console.error(jqXHR, textStatus, errorThrown);
})
}
}, false);
我的manifest.json
文件:
{
"manifest_version": 2,
"name": "MyExtension",
"description": "This extension will for learning",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "index.html"
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["jquery.min.js", "app.js"]
}
],
"permissions": [
"activeTab",
"http://*/",
"https://*/"
]
}
编辑:将https
添加到manifest.json
文件,错误仍然存在。
检查弹出窗口我收到以下错误:
jquery.min.js:4拒绝加载脚本 'https://sitewiththeapi.net/api/searchuser/theuser/show/list.json' 因为它违反了以下内容安全策略指令: “script-src'self'blob:filesystem:chrome-extension-resource:”。
答案 0 :(得分:1)
尝试添加:
"converted_from_user_script": true,
在manifest.json版本之后。
这更像是一种黑客攻击,而不是一种合法的解决方案,但如果您正在为自己开发该扩展或仅仅是为了学习,那就很好了。