V
V
Vadim Bulgakov2016-03-20 23:04:12
JavaScript
Vadim Bulgakov, 2016-03-20 23:04:12

Cross-domain data exchange and jsonp when creating a plugin for Cchrome, how to implement?

I decided to write a plugin for chrome that will display the number of unwatched TV shows on the sizonvar. And I ran into a security policy ... But I successfully dealt with this problem using jsonp.

$.ajax({
    url: "http://seasonvar.ru/jsonMark.php",
    jsonp: "callback",
    dataType: "jsonp",
 
    success: function( response ) {
    	if(response.data.today == undefined)
    	alert(1)
    	else
    		alert(2);
    }
});

This script works (if you are registered with seasonvar, you will be given all the necessary information) on a regular html page.
But then a new problem arose, which I can not reason with. When loading the plugin in chrome, an error appears:
Refused to load the script ' seasonvar.ru/jsonMark.php?callback=jQuery222076483... ' because it violates the following Content Security Policy directive: "script-src 'self' https:// seasonvar.ru/jsonMark.php "
Everywhere they say that it is necessary to add to manifest.json:
"permissions": [" seasonvar.ru "],
"content_security_policy": "script-src 'self' https://seasonvar.ru/jsonMark .php; object-src'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OVK2015, 2016-03-21
@Silector

Here is your option:
background.html

<!doctype html>
<html>
  <head>
    <title></title>
    <script type="text/javaSCRIPT" src="js/jquery-1.11.2.min.js"></script>				
    <script type="text/javaSCRIPT" src="js/background.js"></script>				
  </head>
  <body></body>
</html>

background.js:
$.ajax
({
    url: "http://seasonvar.ru/jsonMark.php",    
    dataType: "json",
 
    success: function( response ) 
    {
    	console.log('old: ' + response.data.old);
    	console.log('noSeries: ' + response.data.noSeries);
    }
});

manifest.json
"background" : 
  {
        "page": "background.html"
    },
  
  "permissions": 
  [			
    "http://seasonvar.ru/*",	
    "tabs"
  ],
"content_security_policy": 
    	"script-src 'self' 'unsafe-eval'; object-src 'self'"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question