简体   繁体   中英

How can I make a POST request in a chrome extension that runs on twitter?

Currently, I am running a content script whenever https://twitter.com/home loads. The content script makes a POST request to my own API server (hosted on AWS) in the content script, using Axios. But I run into the following error:

Access to XMLHttpRequest at '${endpoint url}' from origin 'https://twitter.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I've only just started building chrome extensions so I'm probably doing it completely wrong. Please correct me and let me know how a feature like this could be implemented.

You have 2 options:

  1. Configure your AWS server to provide the CORS policy by adding an Access-Control-Allow-Origin header for example.
  2. Do the request in your background script because CORS policy is not enforced there.

Further reading can be found here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM