Error using Firebase from a Chrome app

I am trying to use Firebase from a Chrome application (and not extensions) and could not get around the following error:

Refused to download script'https: // {my firebase id} .firebaseio.com / .lp? start = t & ser = 81980096 & cb = 15 & v = 5 'because it violates the following content security policy directive: "default-src' self 'chrome-extension-resource:". Note that 'script -src' was not explicitly installed, so 'default-src' is used as a fallback.

My manifest.json file is as follows:

{ "manifest_version": 2, "name": "Simple Demo", "version": "1", "icons": { "128": "icon_128.png" }, "permissions": ["https://*.firebaseio.com/"], "app": { "background": { "scripts": ["background.js"] } }, "minimum_chrome_version": "28" } 

I have a firebase.js script local to a chrome application, it seems that the problem is that it is trying to load other scripts that are not resolved.

Any ideas are welcome.

+5
source share
2 answers

Well, you can use the Firebase REST API, in which case I used for my chrome application and its performance. This does not require the addition of a Firebase SDK!

Read the following docs, https://firebase.googleblog.com/2014/03/announcing-streaming-for-firebase-rest.html

https://firebase.google.com/docs/reference/rest/database/

https://firebase.google.com/docs/database/rest/retrieve-data

The approach is very simple.

The protocol is known as SSE (events sent by the server) , where you listen to a specific server URL and when something changes, you get an event callback.

In this case, firebase officially provides the SSE-based engine.

Code snippet example

  //firebaseUrl will be like https://xxxxx.firebaseio.com/yourNode.json or https://xxxxx.firebaseio.com/yourNode/.json //notice ".json" at the end of URL, whatever node you want to listen, add .json as suffix var firebaseEventSS = new EventSource(firebaseUrl); //and you will have callbacks where you get the data firebaseEventSS.addEventListener("patch", function (e) { var data = e.data; }, false); firebaseEventSS.addEventListener("put", function (e) { var data = e.data; }, false); 

Just check out a few EventSource Examples and combine with the Firebase Doc for the REST API and you're all set!

Remember to close () when this is done.

 firebaseEventSS.close(); 
+1
source

This is an old question, but the solution suggested by the Firebase team is to use a different URL protocol for the database.

Therefore, instead of using https://<app>.firebaseio.com/ you should use wss://<app>.firebaseio.com/ .

I found a solution here . Here is the answer provided by the Firebase team on this .

0
source

Source: https://habr.com/ru/post/1216642/


All Articles