POST request on Facebook.com in Chrome Extension fails

房东的猫 提交于 2019-12-04 02:35:20

问题


I have a Chrome Extension that sends AJAX POST with some data on every page.

The problem is that, Facebook block the AJAX request resulting this:

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".

How to send AJAX call to my server on that page also?

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.

Also, is there some place I can use to store data in Chrome Extension while using content scripts?


回答1:


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.

Also, is there some place I can use to store data in Chrome Extension while using content scripts?

Use the chrome.storage API, or use message passing and localStorage. See this answer for a more detailed explanation and sample code.



来源:https://stackoverflow.com/questions/17011185/post-request-on-facebook-com-in-chrome-extension-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!