Facebook扩展程序中的Chrome扩展程序POST请求失败 [英] POST request on Facebook.com in Chrome Extension fails
问题描述
我有一个Chrome扩展程序,它向每个页面上的一些数据发送AJAX POST。
I have a Chrome Extension that sends AJAX POST with some data on every page.
问题是,Facebook阻止AJAX请求导致:
The problem is that, Facebook block the AJAX request resulting this:
拒绝连接到
'URL_HERE',因为它
违反了以下内容安全策略指令:connect-src
https:// .facebook.com http:// .facebook.com https:// .fbcdn.net
http:// .fbcdn .net * .facebook.net .spotilocal.com:
https:// .akamaihd.net ws:// .facebook.com:* http:
Refused to connect to 'URL_HERE' because it violates the following Content Security Policy directive: "connect-src https://.facebook.com http://.facebook.com https://.fbcdn.net http://.fbcdn.net *.facebook.net .spotilocal.com: https://.akamaihd.net ws://.facebook.com:* http://*.akamaihd.net".
如何在该页面上向我的服务器发送AJAX调用?
How to send AJAX call to my server on that page also?
我是制作Chrome扩展程序的新手,请告诉我是否有可能。我正在使用内容脚本。不知道是否可以使用后台页面进行操作。
I am new to making Chrome Extensions, please tell me if anything is possible. I am using Content Scripts. Not sure if something can be done with background pages.
另外,在使用内容脚本时,我可以使用哪些位置将数据存储在Chrome扩展程序中?
Also, is there some place I can use to store data in Chrome Extension while using content scripts?
推荐答案
当页面的CSP干扰时,执行跨源请求的唯一方法是通过后台页面。您可以在使用后台页面的跨域XMLHttpRequest 找到完整示例。
The only way to perform a cross-origin request when the page's CSP interferes is through a background page. You can find a complete example at Cross-domain XMLHttpRequest using background pages.
另外,在使用内容脚本时,我可以使用哪些位置将数据存储在Chrome扩展程序中?
Also, is there some place I can use to store data in Chrome Extension while using content scripts?
使用 chrome.storage
API或使用消息传递和 localStorage
。有关更详细的解释和示例代码,请参阅此答案。
Use the chrome.storage
API, or use message passing and localStorage
. See this answer for a more detailed explanation and sample code.
这篇关于Facebook扩展程序中的Chrome扩展程序POST请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!