1

I am trying to create a page to show 360 photos I took with my Nexus 6 default camera app in panoramic mode.

Using the Google documentation, I created a local website "video360.dev"

<div id="vrview"></div>

remote hosted libraries seemed to get me further

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>    
<script src="//storage.googleapis.com/vrview/2.0/build/vrview.min.js"></script>

I tried, locally hosted image, image on my domain and an image hosting solution:

<script>
        window.addEventListener('load', onVrViewLoad)
        function onVrViewLoad() {
          var vrView = new VRView.Player('#vrview', {

            //Taken with nexus6 default camera app in panoramic mode
            image: 'http://www.darrencousins.com/images/1.jpg',
            // image: '1.jpg',
            // image: 'https://image.ibb.co/jCpmGQ/1.jpg',

            // video: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/304756/rabbit360_HD_1280x640_low.mp4',

            is_stereo: true,
            width:'100%',
            height:'800px'
          });
        }
    </script>

To make sure I wasn't going mad, I "borrowed" a working video line from an existing codepen, it worked fine, it's just something about my image or hosting setup.

I made a codepen to try and remove the whole "local hosting" issue as I believe I have a CORS issue, but unsure how to solve it.

issue seen when locally hosting

Any ideas how to fix this?

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
sygad1
  • 1,392
  • 3
  • 12
  • 19

1 Answers1

2

Your code’s sending a request for https://image.ibb.co/jCpmGQ/1.jpg using XHR and your browser is getting the response—but the response lacks the Access-Control-Allow-Origin response header, so your browser isn’t allowing your frontend JavaScript code to actually access the response. That’s what browsers do for cross-origin requests when there’s no Access-Control-Allow-Origin response header in the response. That’s how CORS works.

Therefore probably your only option is to send the request through a CORS proxy instead.

So what you can try is, where you’re specifying the URL https://image.ibb.co/jCpmGQ/1.jpg in your code now, just replace that with this URL:

https://cors-anywhere.herokuapp.com/https://image.ibb.co/jCpmGQ/1.jpg

That will cause the request to be sent to https://cors-anywhere.herokuapp.com instead, which is a CORS proxy. That proxy will then send the request for https://image.ibb.co/jCpmGQ/1.jpg and when it gets the response, the proxy will take it and add the Access-Control-Allow-Origin response header to it and then pass that back to your requesting frontend code as the response.

That response with the Access-Control-Allow-Origin response header is what your browser sees, so the error message the browser is showing you now goes away, and the browser allows your frontend JavaScript code to access the response.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
  • Works like a charm, thanks for that. I also temporarily got around the issue by installing a chrome extension to enable CORS, not an ideal solution but at least it confirmed my suspicions. – sygad1 Apr 22 '17 at 06:33
  • 1
    Any idea how to make this work locally? I use MAMP Pro as my server – sygad1 Apr 22 '17 at 06:34
  • 1
    https://www.npmjs.com/package/cors-anywhere is whats used by that heroku server, might be useful if someone wants to host their own – user2312688 Dec 04 '17 at 19:25
  • @user2312688 Thanks yeah I put some more details in the **How to use a CORS proxy to get around “No Access-Control-Allow-Origin header” problems* section of the answer at https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe/43881141#43881141 – sideshowbarker Dec 04 '17 at 20:41
  • Thanks for the answer... till yesterday it was working, from today not working!! is there any logical reason? – noman404 Oct 21 '18 at 15:55
  • https://cors-anywhere.herokuapp.com is designed for temporary projects and debugging, it's not for production projects. Indeed they ended recently free support and they added limitations to usage. – jumpjack Aug 25 '21 at 17:31