LoginSignup
1
1

More than 5 years have passed since last update.

chromeエクステンションでjsonpを読み込みメモ

Last updated at Posted at 2017-07-06

jsonpが利用できるのに読み込んでくれない
because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:".
コンソールにこんなエラーがでるとき

js側

$.ajax({
  type: 'GET',
  url: 'http://localhost:4000/jsonのパス',
  dataType: 'jsonp',
  jsonp: 'callback'
})
.done(function(data){
  console.log("成功");
})
.fail(function(data){
  console.log("エラー");
});

manifest.jsonにいかを追記

"content_security_policy":"script-src 'self' http://localhost:4000; object-src 'self'",

参考

http://noumenon-th.net/programming/2016/03/24/jsonp_jquery/
https://stackoverflow.com/questions/36622181/how-to-fix-chrome-extension-inline-javascript-invocation-error

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1