在Chrome中进行测试时,Chrome扩展程序无法运行:// extensions / [英] Chrome extension don't work when tested in chrome://extensions/

查看:1877
本文介绍了在Chrome中进行测试时,Chrome扩展程序无法运行:// extensions /的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解一些关于google-extensions的知识,所以我试着做一个简单的扩展,使用<$ c向 api 发出请求

当我直接在浏览器(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(函数(数据){
console.log(data);
})

.fail(函数(jqXHR,textStatus,errorThrown){
console.error(jqXHR,textStatus,errorThrown);
})
}
},false);

我的 manifest.json file:

  {
manifest_version:2,

name:MyExtension,
description:此扩展名将用于学习,
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:。



解决方案

尝试添加:

 converted_from_user_script:true,

在manifest.json中的版本之后。



这不仅仅是一种合法的解决方案,而且如果您正在为自己开发扩展程序或仅仅是为了学习,这很好。


I'm trying to learn a little a bit about google-extensions, so I tried to make a simple extension that make a request to an api using ajax then return some results.

When I test directly in the browser(localhost), it works perfectly, but when I try to test adding it to chrome://extensions/ and clicking on Load unpacked extension… in developer mode, it's not working.

This is my app.js with ajax call:

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);

And my manifest.json file:

{
  "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://*/"
   ]
}

EDIT: Added https to manifest.json file and the error persists. Inspecting the popup I got the following error:

jquery.min.js:4 Refused to load the script 'https://sitewiththeapi.net/api/searchuser/theuser/show/list.json' because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:".

解决方案

Try adding:

"converted_from_user_script": true,

After version in your manifest.json.

This is more of a hack than a legit solution but its fine if you are developing that extension for yourself or just to learn.

这篇关于在Chrome中进行测试时,Chrome扩展程序无法运行:// extensions /的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆