I wrote an application in Flutter Web. When I run it in the Browser (debug), I get this error:
cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.googleapis.com/identityto...
When I run it in release mode, I just get this:
Error while fetching an original source: NetworkError when attempting to fetch resource.
Source URL: org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/js_helper.dart
According to this Documentation or this Question I have to add something using Expressjs like:
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors({ origin: true }));
It seems like CORS error is well-known issue in the web field. But I tried flutter web for the first time ever and I faced critical error. The code below worked well in app version when it was running on iOS device, but when i tested the same code on Chrome with web debugging from beta channel, it encountered CORS error.
Before using FlutterFire on the web, you must first import the Firebase JavaScript SDK and initialize Firebase. The only way to currently add the Firebase SDKs to your Flutter web project is by importing the scripts from the Firebase content delivery network (CDN). Add the firebase-app.js script to your index.html file: ...
This CORS proxy solution is only for students or developers learning networking topics in their programming language. When the Flutter web app sends a request to this 3rd party, it adds the necessary CORS header and returns the original server response to the Flutter web app.
It seems that indeed, CORS is blocking you from using Firebase to store and access data. As per the documentation Configuring cross-origin resource sharing (CORS):
It seems that indeed, CORS is blocking you from using Firebase to store and access data. As per the documentation Configuring cross-origin resource sharing (CORS):
Cross Origin Resource Sharing (CORS) is a mechanism for allowing interactions between resources from different origins, something that is normally prohibited in order to prevent malicious behavior.
Considering that, you will need to configure yours to work and accept requests made via HTTP. I would recommend you to take a look at the above documentation and the following links, so you can get more information about it.
Once you have them configured, you should not face both errors anymore, since the requests via HTTP will be authorized via CORS and the access to Firebase should be established.
Let me know if the information helped you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With