Files
react.dev/docs/cross-origin-errors.md
Brian Vaughn 52b694eaae Add new docs website (#10896)
Adds a new docs website, built with Gatsby JS, to replace the old Jekyll site. Source code for the new site lives in /www (although markdown and YML data still comes from the legacy /docs folder).

Changes to either markdown or website source code can be previewed on Netlify. The react-js bot should automatically add comments to each PR with preview links. (This preview is generated by running the newly-added yarn build:docs command in the root package.json.)

The majority of the changes in this PR are contained within the new /www directory. However some minor modifications have been made to existing content in the /docs directory:

* Modified frontmatter author block to always be an array
* Small markdown formatting tweaks
2017-09-28 10:18:04 -07:00

1.8 KiB

id, title, permalink
id title permalink
cross-origin-errors Cross-origin Errors docs/cross-origin-errors.html

Note:

The following section applies only to the development mode of React. Error handling in production mode is done with regular try/catch statements.

In development mode, React uses a global error event handler to preserve the "pause on exceptions" behavior of browser DevTools. It also logs errors to the developer console.

If an error is thrown from a different origin the browser will mask its details and React will not be able to log the original error message. This is a security precaution taken by browsers to avoid leaking sensitive information.

You can simplify the development/debugging process by ensuring that errors are thrown with a same-origin policy. Below are some common causes of cross-origin errors and ways to address them.

CDN

When loading React (or other libraries that might throw errors) from a CDN, add the crossorigin attribute to your <script> tags:

<script crossorigin src="..."></script>

Also ensure the CDN responds with the Access-Control-Allow-Origin: * HTTP header:

Access-Control-Allow-Origin: *

Webpack

Some JavaScript bundlers may wrap the application code with eval statements in development. (For example Webpack will do this if devtool is set to any value containing the word "eval".) This may cause errors to be treated as cross-origin.

If you use Webpack, we recommend using the cheap-module-source-map setting in development to avoid this problem.