Skip to content

Add Emulator Overlay #8977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 60 commits into
base: main
Choose a base branch
from
Open

Add Emulator Overlay #8977

wants to merge 60 commits into from

Conversation

maneesht
Copy link
Contributor

@maneesht maneesht commented Apr 25, 2025

This adds an overlay to the bottom of the user's screen:

image

If the user is connected to the emulator, the image will always be shown. If the user is not connected to the emulator, but is on a cloud workstation, then the user will be shown that they are connected to prod.

Copy link

changeset-bot bot commented Apr 25, 2025

🦋 Changeset detected

Latest commit: 1c4c6ee

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@firebase/auth Patch
@firebase/firestore Patch
@firebase/util Patch
@firebase/database Patch
@firebase/storage Patch
@firebase/functions Patch
@firebase/auth-compat Patch
firebase Patch
@firebase/firestore-compat Patch
@firebase/analytics-compat Patch
@firebase/analytics Patch
@firebase/app-check-compat Patch
@firebase/app-check Patch
@firebase/app-compat Patch
@firebase/app Patch
@firebase/component Patch
@firebase/data-connect Patch
@firebase/database-compat Patch
@firebase/database-types Patch
@firebase/functions-compat Patch
@firebase/installations-compat Patch
@firebase/installations Patch
@firebase/messaging-compat Patch
@firebase/messaging Patch
@firebase/performance-compat Patch
@firebase/performance Patch
@firebase/remote-config-compat Patch
@firebase/remote-config Patch
@firebase/storage-compat Patch
@firebase/vertexai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 25, 2025

Size Report 1

Affected Products

  • @firebase/auth

    TypeBase (6a02778)Merge (88622af)Diff
    browser193 kB193 kB+157 B (+0.1%)
    cordova166 kB166 kB+122 B (+0.1%)
    main147 kB147 kB+111 B (+0.1%)
    module193 kB193 kB+157 B (+0.1%)
    react-native165 kB165 kB+111 B (+0.1%)
  • @firebase/auth-cordova

    TypeBase (6a02778)Merge (88622af)Diff
    browser166 kB166 kB+122 B (+0.1%)
    module166 kB166 kB+122 B (+0.1%)
  • @firebase/auth-web-extension

    TypeBase (6a02778)Merge (88622af)Diff
    browser142 kB142 kB+122 B (+0.1%)
    main159 kB160 kB+115 B (+0.1%)
    module142 kB142 kB+122 B (+0.1%)
  • @firebase/auth/internal

    TypeBase (6a02778)Merge (88622af)Diff
    browser204 kB204 kB+157 B (+0.1%)
    main174 kB174 kB+115 B (+0.1%)
    module204 kB204 kB+157 B (+0.1%)
  • @firebase/database

    TypeBase (6a02778)Merge (88622af)Diff
    browser249 kB250 kB+175 B (+0.1%)
    main254 kB255 kB+169 B (+0.1%)
    module249 kB250 kB+175 B (+0.1%)
  • @firebase/database-compat/standalone

    TypeBase (6a02778)Merge (88622af)Diff
    main366 kB367 kB+125 B (+0.0%)
  • @firebase/firestore

    TypeBase (6a02778)Merge (88622af)Diff
    browser385 kB385 kB+133 B (+0.0%)
    main595 kB595 kB+114 B (+0.0%)
    module385 kB385 kB+133 B (+0.0%)
    react-native385 kB385 kB+137 B (+0.0%)
  • @firebase/firestore-lite

    TypeBase (6a02778)Merge (88622af)Diff
    browser114 kB114 kB+127 B (+0.1%)
    main157 kB157 kB+114 B (+0.1%)
    module114 kB114 kB+127 B (+0.1%)
    react-native114 kB114 kB+130 B (+0.1%)
  • @firebase/functions

    TypeBase (6a02778)Merge (88622af)Diff
    browser14.1 kB14.4 kB+248 B (+1.8%)
    main14.7 kB14.9 kB+247 B (+1.7%)
    module14.1 kB14.4 kB+248 B (+1.8%)
  • @firebase/storage

    TypeBase (6a02778)Merge (88622af)Diff
    browser58.4 kB58.6 kB+150 B (+0.3%)
    main60.0 kB60.1 kB+144 B (+0.2%)
    module58.4 kB58.6 kB+150 B (+0.3%)
  • @firebase/util

    TypeBase (6a02778)Merge (88622af)Diff
    browser23.5 kB28.7 kB+5.25 kB (+22.4%)
    main29.7 kB35.0 kB+5.36 kB (+18.1%)
    module23.5 kB28.7 kB+5.25 kB (+22.4%)
  • bundle

    39 size changes

    TypeBase (6a02778)Merge (88622af)Diff
    auth (Anonymous)77.8 kB77.8 kB+10 B (+0.0%)
    auth (EmailAndPassword)87.9 kB87.9 kB+10 B (+0.0%)
    auth (GoogleFBTwitterGitHubPopup)105 kB109 kB+4.19 kB (+4.0%)
    auth (GooglePopup)102 kB102 kB+10 B (+0.0%)
    auth (GoogleRedirect)102 kB102 kB+10 B (+0.0%)
    auth (Phone)95.3 kB95.4 kB+10 B (+0.0%)
    database (Append to a list of data)150 kB154 kB+4.24 kB (+2.8%)
    database (Filtering data)149 kB153 kB+4.24 kB (+2.8%)
    database (Listen for child events)165 kB170 kB+4.24 kB (+2.6%)
    database (Listen for value events + Detach listeners)165 kB170 kB+4.24 kB (+2.6%)
    database (Listen for value events)165 kB169 kB+4.24 kB (+2.6%)
    database (Read data once)165 kB169 kB+4.24 kB (+2.6%)
    database (Save data as transactions)167 kB172 kB+4.24 kB (+2.5%)
    database (Sort data)151 kB155 kB+4.24 kB (+2.8%)
    database (Write data)149 kB153 kB+4.24 kB (+2.8%)
    firestore (CSI Auto Indexing Disable and Delete)275 kB279 kB+4.21 kB (+1.5%)
    firestore (CSI Auto Indexing Enable)275 kB279 kB+4.21 kB (+1.5%)
    firestore (Persistence)306 kB310 kB+4.21 kB (+1.4%)
    firestore (Query Cursors)252 kB256 kB+4.21 kB (+1.7%)
    firestore (Query)249 kB254 kB+4.21 kB (+1.7%)
    firestore (Read data once)237 kB241 kB+4.21 kB (+1.8%)
    firestore (Read Write w Persistence)331 kB335 kB+4.21 kB (+1.3%)
    firestore (Realtime updates)239 kB244 kB+4.21 kB (+1.8%)
    firestore (Transaction)216 kB221 kB+4.21 kB (+1.9%)
    firestore (Write data)216 kB220 kB+4.21 kB (+1.9%)
    firestore-lite (Query Cursors)105 kB109 kB+4.21 kB (+4.0%)
    firestore-lite (Query)101 kB105 kB+4.21 kB (+4.2%)
    firestore-lite (Read data once)76.3 kB80.5 kB+4.21 kB (+5.5%)
    firestore-lite (Transaction)102 kB106 kB+4.21 kB (+4.1%)
    firestore-lite (Write data)85.9 kB90.1 kB+4.21 kB (+4.9%)
    functions (call)35.0 kB39.2 kB+4.22 kB (+12.1%)
    storage (getBytes)42.8 kB47.0 kB+4.21 kB (+9.8%)
    storage (getDownloadURL)44.9 kB49.1 kB+4.21 kB (+9.4%)
    storage (getMetadata)44.3 kB48.6 kB+4.21 kB (+9.5%)
    storage (list + listAll)43.8 kB48.0 kB+4.21 kB (+9.6%)
    storage (updateMetadata)44.6 kB48.8 kB+4.21 kB (+9.4%)
    storage (uploadBytes)49.5 kB53.7 kB+4.21 kB (+8.5%)
    storage (uploadBytesResumable)59.4 kB63.6 kB+4.21 kB (+7.1%)
    storage (uploadString)49.7 kB53.9 kB+4.21 kB (+8.5%)

  • firebase

    14 size changes

    TypeBase (6a02778)Merge (88622af)Diff
    firebase-auth-compat.js141 kB145 kB+3.95 kB (+2.8%)
    firebase-auth-cordova.js138 kB142 kB+4.26 kB (+3.1%)
    firebase-auth-web-extension.js121 kB125 kB+4.26 kB (+3.5%)
    firebase-auth.js158 kB163 kB+4.30 kB (+2.7%)
    firebase-compat.js797 kB802 kB+4.26 kB (+0.5%)
    firebase-database-compat.js164 kB168 kB+4.02 kB (+2.4%)
    firebase-database.js187 kB192 kB+4.36 kB (+2.3%)
    firebase-firestore-compat.js342 kB346 kB+4.00 kB (+1.2%)
    firebase-firestore-lite.js133 kB137 kB+4.32 kB (+3.3%)
    firebase-firestore.js443 kB448 kB+4.32 kB (+1.0%)
    firebase-functions-compat.js10.5 kB14.6 kB+4.04 kB (+38.3%)
    firebase-functions.js15.0 kB19.4 kB+4.42 kB (+29.5%)
    firebase-storage-compat.js40.1 kB44.1 kB+3.98 kB (+9.9%)
    firebase-storage.js46.7 kB51.0 kB+4.33 kB (+9.3%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/P7DABVbcep.html

@maneesht maneesht requested a review from MarkDuckworth May 5, 2025 21:32
Copy link
Contributor

@MarkDuckworth MarkDuckworth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM(firestore)

emitEmulatorWarning();
}

// Workaround to get cookies in Firebase Studio
if (isCloudWorkstation(host)) {
void pingServer(`${protocol}//${host}${portStr}`);
updateEmulatorBanner('Auth', true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we honor the disableWarnings flag for this banner? I think the way you have it now there's no way for customer to override it

@@ -393,6 +394,7 @@ export function connectDatabaseEmulator(
// Workaround to get cookies in Firebase Studio
if (isCloudWorkstation(host)) {
void pingServer(host);
updateEmulatorBanner('Database', true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto here, we need a way to override this

@@ -198,7 +199,9 @@ export async function _performFetchWithErrorHandling<V>(
customErrorMap: Partial<ServerErrorMap<ServerError>>,
fetchFn: () => Promise<Response>
): Promise<V> {
(auth as AuthInternal)._canInitEmulator = false;
const authInternal = auth as AuthInternal;
updateEmulatorBanner('Auth', authInternal.emulatorConfig !== null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to update this on every call? or just when we do the ping?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about when the user connects to prod?

if (document.readyState === 'loading') {
window.addEventListener('DOMContentLoaded', setupDom);
} else {
setupDom();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this trigger every time i make an API request? can we cache it somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not anymore. I refactored to only call updateEmulatorBanner upon get[Product] and connect[Product].
Here are the flows I tested:

getProduct(); // update banner to prod
connectEmulator(); // update banner to emulator
getProduct(); // No Op because previously the product was connected to the emulator, and you can't un-connect to the emulator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants