Paper.js: Cannot load from external file because of CORS restriction

Created on 9 Feb 2015  路  5Comments  路  Source: paperjs/paper.js

When I am trying to load an external script like in the examples, I am getting CORS related errors with 0.9.21 and 0.9.19.

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="css/style.css">
  <script type="text/javascript" src="js/paper-full.js"></script>
  <!-- // <script type="text/javascript" src="js/paper-full-0.9.21.js"></script> -->
  <script type="text/paperscript" src="js/main.js" canvas="canvas"></script>
  </script>
</head>
<body>
  <canvas id="canvas" resize></canvas>

</body>
</html>

Most helpful comment

Maybe you want to take a look at this:

https://www.npmjs.com/package/http-server

I use it when testing our software on my localhost to prevent cross origin errors.

All 5 comments

Are you sure this is a paper.js issue? Maybe you are trying to load a resource from the local file system, which Chrome does not permit.

Did you try the same with Firefox? It seems to be less restrictive.

Maybe you want to take a look at this:

https://www.npmjs.com/package/http-server

I use it when testing our software on my localhost to prevent cross origin errors.

Yeah there is no way we can circumvent CORS when on the file system. You can serve the files from a local web server, or start the browser with a flag that allows it to load from the local file system:

http://stackoverflow.com/questions/4208530/xmlhttprequest-origin-null-is-not-allowed-access-control-allow-origin-for-file

On OSX you can also use http://anvilformac.com/ to serve a local folder through a local web-server very conveniently.

You can still force a chrome instance to allow CORS by adding the cmd line argument --disable-web-security.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

przyb picture przyb  路  5Comments

nicholaswmin picture nicholaswmin  路  3Comments

tjunnone picture tjunnone  路  4Comments

eugene-rozov picture eugene-rozov  路  6Comments

sansumbrella picture sansumbrella  路  3Comments