I am looking for a way to run a Tamper Monkey script on a Facebook page that regularly checks a database for new data and performs certain actions. I have attempted to implement polling using AJAX, and below is the code I used:
(function poll() {
setTimeout(function() {
$.ajax({
url: "xyz",
headers: {
'Content-Type': 'application/json',
'x-apikey': apiKey,
'cache-control': 'no-cache'
},
type: "GET",
success: function(data) {
// check if null return (no results from API)
if (data == null) {
console.log('no data!');
} else {
console.log(data);
},
dataType: "json",
complete: poll,
timeout: 2000
});
}, 3000);
})();
However, when I try to execute the script, I encounter the following error:
Refused to connect to 'xyz' because it violates the following Content Security Policy directive: "connect-src *.facebook.com facebook.com *.fbcdn.net *.facebook.net .spotilocal.com: .akamaihd.net wss://.facebook.com:* https://fb.scanandcleanlocal.com:* .atlassolutions.com attachment.fbsbx.com ws://localhost: blob: *.cdninstagram.com 'self' chrome-extension://boadgeojelhgndaghljhdicfkmllpafd chrome-extension://dliochdbjfkdbacpmhlcpmleaejidimm".
I understand that this error is due to the content security policy directive set by Facebook.
Is there an alternative approach I can take to implement polling? I looked into Grease Monkey's GM.xmlHttpRequest but couldn't figure out how to do polling without using AJAX.
Any help would be greatly appreciated.