Hi,
I have been building a chrome extension for the last couple of weeks but now I'm facing an issue when trying to use firebase_core plugin.
I am trying to connect to firebase DB to be able to add/retrieve data using cloud_firestore plugin.
In order to use cloud_firestore funtionalities like FirebaseFirestore.instance.collection, I would first need to initialize firebase by calling:
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.web,
);
I call this in my main.dart file.
When using the code above, a CSP error occurs. Which says the following:
________________________
main.dart.js:42836 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-Fao661ADUxDSmVdFYUQXNSBGfMlW96o7X2IgkxhpC9E='), or a nonce ('nonce-...') is required to enable inline execution.
________________________
If I don't initialize Firebase, then this error does not occur, but then, I can't use cloud_firestore.
Here's my manifest.json file:
___________
{
"name": "assistant",
"short_name": "assistant",
"description": "A new Flutter project.",
"version": "1.0.0",
"content_security_policy": {
"extension_pages": "script-src 'self' ; object-src 'self'"
},
"action": {
"default_popup": "index.html",
"default_icon": "icons/Icon-192.png"
},
"manifest_version": 3,
"permissions":[
"identity"
]
}
____________
When I'm building my project in VS Code, I'm using this command:
flutter build web --web-renderer html --csp
I have looked for a solution everywhere,
here,
here and
here. But I am still unable to solve this issue.
I also saw
this, which seems that the person who is proposing this solution has made it work for him. But since I am not familiar with javascript, I couldn't understand exactly what he did.
Btw, here are my dependencies from firebase:
firebase_core: ^2.8.0
cloud_firestore: ^4.4.5
Is there a "clean" way to solve this issue? I have spent a lot of time trying to solve it without any success :(
Any help will be greatly appreciated!