-
-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with web : Error: XMLHttpRequest error. #119
Comments
If you read in the browser console you should get something the The only way to workaround this issue would be to implement a custom http client that acts as a middleware and redirects instead the requests a server of yours (maybe see https://github.com/Rob--W/cors-anywhere )and then to the youtube api. This might not be a trivial task to do if you don't know where to look for, and have not prior experiences implementing custom http clients and this kind of stuff. |
ok thanks for clarification. So this means https://pub.dev/packages/youtube_explode_dart does not support "web". The package compatibility information is misleading. |
I cannot change that, since the package can be compiled in web, the thing is that then the requests cannot be successfully made to the youtube endpoint |
@Hexer10, just out of interest, have you tried to use embed youtube URLs? So instead of https://www.youtube.com/watch?v=cP5fnXQfaao => https://www.youtube.com/embed/cP5fnXQfaao |
@M123-dev That is already implemented in the library, first the data is fetched from the watchpage, and if that fails from the embed page |
Using middleware like https://cors-anywhere.herokuapp.com , that you said, works in flutterweb, but you need to modify the code in search_page, for add it when get 'https://www.youtube.com/results?search..'. something like that: thanks for the package! ^_^ |
But is it not just possible to add header to your get request to allow cross origins ?
https://fluttercorner.com/flutter-web-getting-xmlhttprequest-error-while-making-http-call/ |
For anyone looking at this issue, you can use the iframe based youtube package on web https://github.com/sarbagyastha/youtube_player_flutter/tree/develop/packages/youtube_player_iframe which does not provide the flexibility of getting the actual stream etc. Though the iframe based version does not work on macos because it is using webview. macos already have webview (endorsed) https://pub.dev/packages/webview_flutter_wkwebview, some methods such as setting background are missing sarbagyastha/youtube_player_flutter#624 For macos, using the video stream from youtube_explode works with video_player package on macos (NOTE: the highest quality is video only, audio is another stream). As for CORS, the CORS header is set by youtube to not allow other domains (e.g. yourapp.com to access its resources). Setting HTTP headers for your own applications does not work, it only allows yourotherapp.com to access yourapp.com. In theory you can ask your user to disable CORS https://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome In practice I think people don't know how to do it will find alternatives and people knowing how to do that will refuse to do so because they know there is security risk. |
Describe the bug
The library cannot send requests in flutter web.
Stacktrace:
The text was updated successfully, but these errors were encountered: