Access to fetch at 'https://www.youtube.com/watch?v=04GiqLjRO3A&hl=en' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin'
ophirgal opened this issue · comments
I created a fresh new react app with create-react-app and tried running the usage example given in the README and I get the following error:
Access to fetch at 'https://www.youtube.com/watch?v=04GiqLjRO3A&hl=en'
from origin 'http://localhost:3000' has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
If an opaque response serves your needs,
set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Is there any way around that?
I know that usually when calling fetch you can pass {mode: 'no-cors'} to solve that but I have no idea where the fetch is hapenning inside the library...
Any help would be greatly appreciated thanks!!
UPDATE:
I realized that I should use the requestOptions property by setting it to {mode: 'no-cors'}, so I tried that, but I get the following error:
Uncaught (in promise) TypeError: Cannot read property 'thumbnails' of undefined
at Object.push../node_modules/react-native-ytdl/lib/info-extras.js.exports.cleanVideoDetails (info-extras.js:258)
at push../node_modules/react-native-ytdl/lib/info.js.exports.getBasicInfo
Any thoughts?
UPDATE:
I edited the source code to avoid this error, and now it seems the request is going through successfully, but I get :
Error: This video is unavailable
at index.js:52
at new Promise ()
at getURLsFromInfoCallback (index.js:42)
at index.js:16
This library wont work on react. It's a react-native library #52
Thanks!