Home > Backend Development > Golang > Why Does My Firefox OS App Get a 'Cross-Origin Request Blocked' Error Even with CORS Enabled?

Why Does My Firefox OS App Get a 'Cross-Origin Request Blocked' Error Even with CORS Enabled?

Mary-Kate Olsen
Release: 2024-12-17 00:13:25
Original
946 people have browsed it

Why Does My Firefox OS App Get a

Cross-Origin Request Blocked Due to XMLHttpRequest Restriction

Question:

Attempting to access a RESTful POST service from a Firefox OS app results in a "Cross-Origin Request Blocked" error, even though the back-end server has set "Access-Control-Allow-Origin: *" in its HTTP response headers.

Solution:

The issue lies in the JavaScript code creating the XMLHttpRequest request:

var request = new XMLHttpRequest();
Copy after login

To make cross-site POST requests in a Firefox OS app, the XMLHttpRequest object must be created in privileged mode, using mozSystem:

var request = new XMLHttpRequest({mozSystem: true});
Copy after login

Implementation Details:

  1. mozSystem: Setting mozSystem to true permits cross-site connections without needing CORS server-side configuration. However, it requires setting mozAnon: true, which prevents sending cookies or other user credentials. This feature is only available to privileged (reviewed) apps and not arbitrary web pages.
  2. Manifest Update: To grant your app the necessary permission, include the following line in your manifest's "permissions" section:
"permissions": {
       "systemXHR" : {},
}
Copy after login

By implementing these changes, your Firefox OS app will be able to make cross-origin POST requests to your Go service.

The above is the detailed content of Why Does My Firefox OS App Get a 'Cross-Origin Request Blocked' Error Even with CORS Enabled?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template