metadata_fetch icon indicating copy to clipboard operation
metadata_fetch copied to clipboard

Doesn't work for Flutter Web, fails with XMLHttpRequest error

Open oianmol opened this issue 3 years ago • 6 comments

Stack Trace

` Error: XMLHttpRequest error. dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 906:28 get current packages/http/src/browser_client.dart 71:22 dart-sdk/lib/async/zone.dart 1612:54 runUnary dart-sdk/lib/async/future_impl.dart 152:18 handleValue dart-sdk/lib/async/future_impl.dart 704:44 handleValueCallback dart-sdk/lib/async/future_impl.dart 733:13 _propagateToListeners dart-sdk/lib/async/future_impl.dart 530:7 [_complete] dart-sdk/lib/async/stream_pipe.dart 61:11 _cancelAndValue dart-sdk/lib/async/stream.dart 1219:7 dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 324:14 _checkAndCall dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 329:39 dcall dart-sdk/lib/html/dart2js/html_dart2js.dart 37307:58

at Object.createErrorWithStack (http://localhost:53250/dart_sdk.js:5348:12)
at Object._rethrow (http://localhost:53250/dart_sdk.js:39350:16)
at async._AsyncCallbackEntry.new.callback (http://localhost:53250/dart_sdk.js:39344:13)
at Object._microtaskLoop (http://localhost:53250/dart_sdk.js:39176:13)
at _startMicrotaskLoop (http://localhost:53250/dart_sdk.js:39182:13)
at http://localhost:53250/dart_sdk.js:34689:9`

I tried to run the sample code and it fails, Is this a known bug ?

oianmol avatar Mar 13 '21 06:03 oianmol

Same issue happened to me, is there any workaround or solution?

ziadshebl avatar May 25 '21 15:05 ziadshebl

Your backend must have an endpoint that accepts OPTIONS request (it's called a Preflight request) and send response with status code 204 to it. Literally if you request GET https://example.com/users/profile a browser will first try to do it with OPTIONS https://example.com/users/profile and when it gets 204 then it will try GET. Make sure your backend can process it

caseyryan avatar May 25 '21 15:05 caseyryan

Then why does it work with flutter mobile ?

On Tue, May 25, 2021, 9:23 PM Konstantin Serov @.***> wrote:

Your backend must have an endpoint that accepts OPTIONS request (it's called a Preflight request) and send response with status code 204 to it. Literally if you request GET https://example.com/users/profile a browser will first try to do it with OPTIONS https://example.com/users/profile and when it gets 204 then it will try GET. Make sure your backend can process it

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jg-l/metadata_fetch/issues/26#issuecomment-847989550, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBQRDMAR47RLP6CSYJG6ILTPPBWTANCNFSM4ZDQQR4A .

oianmol avatar May 25 '21 16:05 oianmol

Because Flutter mobile is not a browser. Only web browsers send Preflight requests. Google "preflight request" if you want to know more

caseyryan avatar May 25 '21 23:05 caseyryan

this solves the issue for testing locally

https://stackoverflow.com/questions/65630743/how-to-solve-flutter-web-api-cors-error-only-with-dart-code

mirrorlink avatar Sep 01 '21 23:09 mirrorlink

I have the same issue, and we are going across sites to fetch meta data. For example, if someone posts a YouTube link. How can we get around this?

ollyde avatar Apr 26 '22 15:04 ollyde