firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.83k stars 891 forks source link

questions #6266

Closed marcusx2 closed 2 years ago

marcusx2 commented 2 years ago

I promise to keep only this issue open for questions that might arise.

  1. How can I use the setLogLevel function? Same question for registerVersion and onLog. I didn't find any examples of these functions online. I am struggling to understand their purpose and how to use them.
  2. Do all errors thrown inherit from FirebaseError? Even when not explicitly said so? For example, the deleteApp method throws an error if I don't call initializeApp beforehand, but this isn't documented.
google-oss-bot commented 2 years ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

jbalidiong commented 2 years ago

Hi @marcusx2, thanks for reaching out. I noticed that some of your questions are about how to use the API, you can use our support channel for these types of inquiries. However, checking our documents, we don't have an example for it. Here is a code snippet on how to use the setLogLevel() and onLog():

import { initializeApp, setLogLevel, onLog} from 'firebase/app';

initializeApp(firebaseConfig);
setLogLevel('debug');

onLog((e) => {
    const { level, message } = e;
      if (level === 'warn') {
        console.log('connection interruption after intial load was success:', message);
      }
      if (level === 'error') {
        console.log('no connection on inital load:', message);
      }
      if(level === 'debug') {
          console.log('debugging logs:', message);
      }
      if(level === 'info') {
          console.log('info: ', message);
      }
  });

As stated in our documents, " setLogLevel() will set the log level for all Firebase SDK and all of the log types above the current log level are captured". And you can use the onLog() to setup custom log handler.

Regarding registerVersion(), we're using it for internal purposes and it's publicly exposed because some frameworks also use it for their internal metrics.

For the FirebaseError, we aim to make it so that all errors thrown by the SDK are wrapped in FirebaseError but there will always be exceptions that we don't catch and wrap. I'll be closing this for now. Feel free to comment and reopen this issue if you're able to find one, please let us know and we'll add it to our to-do list.

marcusx2 commented 2 years ago

@jbalidiong @sam-gc @hsubox76

  1. How can I know that firebase v9 libraries were loaded? For example, if I have code like
    var s = document.createElement('script');
    s.type = 'module';
    var code = 'import * as firebaseApp from "https://www.gstatic.com/firebasejs/9.6.10/firebase-app.js"; window["FirebaseWebGL"].firebaseApp = firebaseApp;';
    try {
    s.appendChild(document.createTextNode(code));
    document.body.appendChild(s);
    } catch (e) {
    s.text = code;
    document.body.appendChild(s);
    }

    I store the firebase scripts in window because I need to use them elsewhere. But I am importing from a CDN, how can I know that the library was already loaded an ready to use? Thanks!

Just to give you more context, I am making a webgl plugin to use firebase in Unity(I'm a plugin developer). That code is in a .jspre file to load firebase. Then I make the bindings using .jslib files. It's all working fine, but I think it's coincidence that the libraries are being loaded in time, so I think I should be able to check that they were loaded.

Also, if there's a better way to do this than storing the libraries in window please let me know. But I can't seem to be able to access the libraries in the jslib files without doing it through window.

In fact, I guess I'll just post the whole .jspre file here. Like I said, it's working fine, but I can't tell if the libraries were already loaded and I'm not sure if the window solution is the best one here.

(
function() {
window["FirebaseWebGL"] = window["FirebaseWebGL"] || {};

var currentVersion = "9.6.10";
window["FirebaseWebGL"].enableProducts = {
    analytics:             false,
    appCheck:              false,
    authentication:        true,
    cloudFirestore:        false,
    cloudFunctions:        false,
    cloudMessaging:        false,
    cloudStorage:          true,
    performanceMonitoring: false,
    realtimeDatabase:      false,
    remoteConfig:          false
};

var s = document.createElement('script');
s.type = 'module';
var code = 'import * as firebaseApp from "https://www.gstatic.com/firebasejs/' + currentVersion + '/firebase-app.js"; window["FirebaseWebGL"].firebaseApp = firebaseApp;';
window["FirebaseWebGL"].enableProducts.analytics && (code += 'import * as firebaseAnalytics from "https://www.gstatic.com/firebasejs/' + currentVersion + '/firebase-analytics.js"; window["FirebaseWebGL"].firebaseAnalytics = firebaseAnalytics;');
window["FirebaseWebGL"].enableProducts.appCheck && (code += 'import * as firebaseAppCheck from "https://www.gstatic.com/firebasejs/' + currentVersion + '/firebase-app-check.js"; window["FirebaseWebGL"].firebaseAppCheck = firebaseAppCheck;');
window["FirebaseWebGL"].enableProducts.authentication && (code += 'import * as firebaseAuth from "https://www.gstatic.com/firebasejs/' + currentVersion + '/firebase-auth.js"; window["FirebaseWebGL"].firebaseAuth = firebaseAuth;');
window["FirebaseWebGL"].enableProducts.cloudFirestore && (code += 'import * as firebaseFirestore from "https://www.gstatic.com/firebasejs/' + currentVersion + '/firebase-firestore.js"; window["FirebaseWebGL"].firebaseFirestore = firebaseFirestore;');
window["FirebaseWebGL"].enableProducts.cloudFunctions && (code += 'import * as firebaseFunctions from "https://www.gstatic.com/firebasejs/' + currentVersion + '/firebase-functions.js"; window["FirebaseWebGL"].firebaseFunctions = firebaseFunctions;');
window["FirebaseWebGL"].enableProducts.cloudMessaging && (code += 'import * as firebaseMessaging from "https://www.gstatic.com/firebasejs/' + currentVersion + '/firebase-messaging.js"; window["FirebaseWebGL"].firebaseMessaging = firebaseMessaging;');
window["FirebaseWebGL"].enableProducts.cloudStorage && (code += 'import * as firebaseStorage from "https://www.gstatic.com/firebasejs/' + currentVersion + '/firebase-storage.js"; window["FirebaseWebGL"].firebaseStorage = firebaseStorage;');
window["FirebaseWebGL"].enableProducts.performanceMonitoring && (code += 'import * as firebasePerformance from "https://www.gstatic.com/firebasejs/' + currentVersion + '/firebase-performance.js"; window["FirebaseWebGL"].firebasePerformance = firebasePerformance;');
window["FirebaseWebGL"].enableProducts.realtimeDatabase && (code += 'import * as firebaseDatabase from "https://www.gstatic.com/firebasejs/' + currentVersion + '/firebase-database.js"; window["FirebaseWebGL"].firebaseDatabase  = firebaseDatabase ;');
window["FirebaseWebGL"].enableProducts.remoteConfig && (code += 'import * as firebaseRemoteConfig from "https://www.gstatic.com/firebasejs/' + currentVersion + '/firebase-remote-config.js"; window["FirebaseWebGL"].firebaseRemoteConfig  = firebaseRemoteConfig ;');

try {
  s.appendChild(document.createTextNode(code));
  document.body.appendChild(s);
} catch (e) {
  s.text = code;
  document.body.appendChild(s);
}

})();
hsubox76 commented 2 years ago

As mentioned above, for questions about how to best use Firebase, try contacting the support channel:

Hi @marcusx2, thanks for reaching out. I noticed that some of your questions are about how to use the API, you can use our support channel for these types of inquiries.

Or other sources of development expertise such as Stack Overflow. We also have a discussion board in this repo, but it may have less frequent replies.

If you find a bug, or something that might be a bug, feel free to open an issue for it.

marcusx2 commented 2 years ago

What category should I pick? None of them seem appropriate for my question. Stackoverflow's firebase section doesn't seem very helpful either since I made a question and nobody replied.

The most help I got was from here. I promise I won't bother you guys much, I created just this issue for my questions. Can you please help me? I promise I won't make a question again for at least 6 months. I will truly try not to bother you guys. Thanks for your understanding.