Cannot connect to firebase db

app works when deployed to the cloud. can’t connect to firebase in Google AI. "
@firebase/firestore:" “Firestore (10.12.2): Could not reach Cloud Firestore backend. Backend didn’t respond within 10 seconds.\nThis typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.” "

How I’m loading :

  <script src="https://www.gstatic.com/firebasejs/10.12.2/firebase-app-compat.js"></script>
  <script src="https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore-compat.js"></script>
  <script src="https://www.gstatic.com/firebasejs/10.12.2/firebase-storage-compat.js"></script>
    // Initialize the app if it hasn't been already.
    if (!firebase.apps.length) {
        firebase.initializeApp(firebaseConfig);
    }

    // Set log level to 'error' to suppress verbose console output and prevent crashes
    // from the SDK trying to log complex objects with circular references.
    firebase.setLogLevel('error');
    
    const app = firebase.app(); // Get the default app instance
    const db = firebase.firestore();
    
    // Enable long polling to resolve connection issues in restrictive environments.
    // Explicitly disable auto-detection to resolve the conflict.
    // The { merge: true } option prevents overriding default settings like the host.
    db.settings({ 
        experimentalForceLongPolling: true, 
        experimentalAutoDetectLongPolling: false, 
        merge: true 
    });
    
    const storage = firebase.storage();
    
    firebaseServices = { app, db, storage };
    
    return firebaseServices;

Hi @deseipel,

Welcome to the Forum,

For assistance with Firebase-related issues, please submit your inquiry at Firebase Support.

Thank you!

While working with the Google AI Studio app, I’ve encountered several integration challenges with Firebase, particularly with Firestore database connectivity. The platform seems to lack full support for environment variables (.env), and service workers to run reliably has been problematic.

This has led to frequent error-correction loops, where fixed files are repeatedly flagged and changed by automated processes—often resulting in application crashes and preview errors. These issues can be discouraging and consume a great deal of development time and energy.

Most importantly, there’s a real opportunity for improvement in Google’s documentation and community support. It would be incredibly helpful if Google could clarify whether AI Studio is meant primarily for prototyping or if production-grade support is on the roadmap. Transparent communication and comprehensive guides would greatly benefit developers who are eager to build robust applications on this platform.

I’d welcome more active dialogue and guidance from Google’s team and fellow developers. By working together—with clearer resources and community engagement—we can help make AI Studio more reliable and rewarding for everyone.

Google AI Studio support is directing us to Firebase support, while Firebase support is telling us to contact Google AI Support, creating a bit of a loop. I reached out to Firebase Support and received a general response, but nothing concrete on how to add Firebase authentication within apps in the Google AI Studio environment. I think we also need help from the Google AI Studio support team on this, as Firebase support hasn’t provided enough detail to resolve our questions about Firebase authentication and Firestore integration.

3 Likes