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 61 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
02c52c6
Added test project to fdc
maneesht Apr 11, 2025
37d0f18
Fixed formatting
maneesht Apr 11, 2025
a4d7813
Fix linting
maneesht Apr 11, 2025
170b15a
Excluded example integration from tsconfig
maneesht Apr 11, 2025
ec405ae
Fixed example-integration package.json
maneesht Apr 11, 2025
248f654
Added ssl check for firestore
maneesht Apr 23, 2025
14ef1bc
Added ssl checks for RTDB
maneesht Apr 23, 2025
a8fe7de
Merge remote-tracking branch 'origin/main' into mtewani/add-ssl-check…
maneesht Apr 23, 2025
df4a115
Removed unnecessary files
maneesht Apr 23, 2025
f867d3b
Removed unnecessary data connect changes
maneesht Apr 23, 2025
4f23f33
Create gentle-laws-kneel.md
maneesht Apr 23, 2025
55b1c0a
Added code to pass on credentials if using a cloud workstation
maneesht Apr 23, 2025
e0a59c5
Create nine-pugs-crash.md
maneesht Apr 23, 2025
8d93780
Addressed comments
maneesht Apr 24, 2025
78142b9
Merge branch 'mtewani/fix-auth-redirects-studio' of https://github.co…
maneesht Apr 24, 2025
5e76a0a
Removed unused import
maneesht Apr 24, 2025
b8b485d
include storage changes
maneesht Apr 24, 2025
21ecf95
Updated api review
maneesht Apr 24, 2025
24c1575
Removed unnecessary import
maneesht Apr 25, 2025
7c7f3ae
Fix formatting
maneesht Apr 25, 2025
d62409a
Fixed data connect test
maneesht Apr 25, 2025
82faa08
Included extra url in externs
maneesht Apr 25, 2025
32c461a
Fixed fdc tests
maneesht Apr 25, 2025
da5b7bf
Passed in emulator information
maneesht Apr 25, 2025
b424e58
Fixed formattign
maneesht Apr 25, 2025
7d2313f
WIP
maneesht Apr 25, 2025
6e0761d
Added emulator status
maneesht Apr 25, 2025
e7b292d
Removed firebaseapp import
maneesht Apr 25, 2025
beff97f
Merge remote-tracking branch 'origin/main' into mtewani/add-emulator-…
maneesht May 1, 2025
6ca5c24
Removed app check change
maneesht May 1, 2025
6d0af9d
Removed eslintrc change
maneesht May 1, 2025
445c490
Removed unnecessary test
maneesht May 1, 2025
d97337f
Fixed failing tests
maneesht May 1, 2025
8f6167e
WIP
maneesht May 5, 2025
0aede90
Implemented emulator overlay
maneesht May 5, 2025
0d05eeb
Merge remote-tracking branch 'origin/main' into mtewani/add-emulator-…
maneesht May 5, 2025
fa3a56f
Removed changeset
maneesht May 5, 2025
6cff61f
Create three-singers-wonder.md
maneesht May 5, 2025
9a4d8ba
Merge branch 'mtewani/add-emulator-overlay' of https://github.com/fir…
maneesht May 5, 2025
eeebee1
Removed unused line
maneesht May 5, 2025
c439abe
Removed unnecessary changes
maneesht May 5, 2025
adb9c76
Updated storage changeset
maneesht May 5, 2025
32433f3
Fixed button click
maneesht May 5, 2025
1db0a40
Fixed linting errors
maneesht May 5, 2025
25f3a21
fixed formatting
maneesht May 5, 2025
b0e7566
Addressed comments
maneesht May 5, 2025
8d70b12
Removed extra document check
maneesht May 5, 2025
bffdabd
Removed extra export
maneesht May 5, 2025
cdbf663
Trigger Build
maneesht May 5, 2025
927dadd
Fixed formatting
maneesht May 5, 2025
83b84f0
Addressed comments
maneesht May 6, 2025
c824b35
Fixed linting
maneesht May 6, 2025
9ee4aa0
Fixed linting
maneesht May 6, 2025
1e7039a
Updated to only trigger on Studio
maneesht May 6, 2025
2e57ab7
Fixed linting
maneesht May 6, 2025
c2246ca
Trigger Build
maneesht May 6, 2025
fe1264c
Persisted dismiss
maneesht May 6, 2025
a3edf83
Removed change to check every request
maneesht May 7, 2025
db73a96
Used disableWarnings in auth
maneesht May 7, 2025
1c4c6ee
Fixed linting
maneesht May 7, 2025
3a4ba47
Fixed linting
maneesht May 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/three-singers-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@firebase/auth": patch
"@firebase/firestore": patch
"@firebase/util": patch
"@firebase/database": patch
"@firebase/storage": patch
"@firebase/functions": patch
---

Add Emulator Overlay
3 changes: 3 additions & 0 deletions common/api-review/util.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ export interface Subscribe<T> {
// @public (undocumented)
export type Unsubscribe = () => void;

// @public
export function updateEmulatorBanner(name: string, isRunningEmulator: boolean): void;

// Warning: (ae-missing-release-tag) "validateArgCount" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
Expand Down
3 changes: 2 additions & 1 deletion packages/auth/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ export async function _performFetchWithErrorHandling<V>(
customErrorMap: Partial<ServerErrorMap<ServerError>>,
fetchFn: () => Promise<Response>
): Promise<V> {
(auth as AuthInternal)._canInitEmulator = false;
const authInternal = auth as AuthInternal;
authInternal._canInitEmulator = false;
const errorMap = { ...SERVER_ERROR_MAP, ...customErrorMap };
try {
const networkTimeout = new NetworkTimeout<Response>(auth);
Expand Down
13 changes: 11 additions & 2 deletions packages/auth/src/core/auth/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import { Auth } from '../../model/public_types';
import { AuthErrorCode } from '../errors';
import { _assert } from '../util/assert';
import { _castAuth } from './auth_impl';
import { deepEqual, isCloudWorkstation, pingServer } from '@firebase/util';
import {
deepEqual,
isCloudWorkstation,
pingServer,
updateEmulatorBanner
} from '@firebase/util';

/**
* Changes the {@link Auth} instance to communicate with the Firebase Auth Emulator, instead of production
Expand Down Expand Up @@ -98,7 +103,11 @@ export function connectAuthEmulator(
authInternal.settings.appVerificationDisabledForTesting = true;

if (!disableWarnings) {
emitEmulatorWarning();
if (isCloudWorkstation(host)) {
updateEmulatorBanner('Auth', true);
} else {
emitEmulatorWarning();
}
}

// Workaround to get cookies in Firebase Studio
Expand Down
8 changes: 7 additions & 1 deletion packages/auth/src/platform_browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import { browserSessionPersistence } from './persistence/session_storage';
import { indexedDBLocalPersistence } from './persistence/indexed_db';
import { browserPopupRedirectResolver } from './popup_redirect';
import { Auth, User } from '../model/public_types';
import { getDefaultEmulatorHost, getExperimentalSetting } from '@firebase/util';
import {
getDefaultEmulatorHost,
getExperimentalSetting,
updateEmulatorBanner
} from '@firebase/util';
import { _setExternalJSProvider } from './load_js';
import { _createError } from '../core/util/assert';
import { AuthErrorCode } from '../core/errors';
Expand Down Expand Up @@ -107,6 +111,8 @@ export function getAuth(app: FirebaseApp = getApp()): Auth {
}
}

updateEmulatorBanner('Auth', false);

const authEmulatorHost = getDefaultEmulatorHost('auth');
if (authEmulatorHost) {
connectAuthEmulator(auth, `http://${authEmulatorHost}`);
Expand Down
9 changes: 8 additions & 1 deletion packages/database/src/api/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
EmulatorMockTokenOptions,
getDefaultEmulatorHostnameAndPort,
isCloudWorkstation,
pingServer
pingServer,
updateEmulatorBanner
} from '@firebase/util';

import { AppCheckTokenProvider } from '../core/AppCheckTokenProvider';
Expand Down Expand Up @@ -257,6 +258,10 @@ export class Database implements _FirebaseService {
this.app.options['databaseAuthVariableOverride']
);
this._instanceStarted = true;
updateEmulatorBanner(
'Database',
this._repo.repoInfo_.emulatorOptions !== null
);
}
return this._repoInternal;
}
Expand Down Expand Up @@ -328,6 +333,7 @@ export function getDatabase(
identifier: url
}) as Database;
if (!db._instanceStarted) {
updateEmulatorBanner('Database', false);
const emulator = getDefaultEmulatorHostnameAndPort('database');
if (emulator) {
connectDatabaseEmulator(db, ...emulator);
Expand Down Expand Up @@ -393,6 +399,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

}

// Modify the repo to apply emulator settings
Expand Down
11 changes: 8 additions & 3 deletions packages/firestore/src/lite-api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
EmulatorMockTokenOptions,
getDefaultEmulatorHostnameAndPort,
isCloudWorkstation,
updateEmulatorBanner,
pingServer
} from '@firebase/util';

Expand Down Expand Up @@ -142,6 +143,7 @@ export class Firestore implements FirestoreService {

_freezeSettings(): FirestoreSettingsImpl {
this._settingsFrozen = true;
updateEmulatorBanner('Firestore', this._settings.isUsingEmulator);
return this._settings;
}

Expand Down Expand Up @@ -334,9 +336,7 @@ export function connectFirestoreEmulator(
emulatorOptions: firestore._getEmulatorOptions()
};
const newHostSetting = `${host}:${port}`;
if (useSsl) {
void pingServer(`https://${newHostSetting}`);
}

if (settings.host !== DEFAULT_HOST && settings.host !== newHostSetting) {
logWarn(
'Host has been set in both settings() and connectFirestoreEmulator(), emulator host ' +
Expand All @@ -357,6 +357,11 @@ export function connectFirestoreEmulator(

firestore._setSettings(newConfig);

if (useSsl) {
void pingServer(`https://${newHostSetting}`);
updateEmulatorBanner('Firestore', true);
}

if (options.mockUserToken) {
let token: string;
let user: User;
Expand Down
4 changes: 3 additions & 1 deletion packages/functions/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
} from './service';
import {
getModularInstance,
getDefaultEmulatorHostnameAndPort
getDefaultEmulatorHostnameAndPort,
updateEmulatorBanner
} from '@firebase/util';

export { FunctionsError } from './error';
Expand All @@ -47,6 +48,7 @@ export function getFunctions(
app: FirebaseApp = getApp(),
regionOrCustomDomain: string = DEFAULT_REGION
): Functions {
updateEmulatorBanner('Functions', false);
// Dependencies
const functionsProvider: Provider<'functions'> = _getProvider(
getModularInstance(app),
Expand Down
9 changes: 8 additions & 1 deletion packages/functions/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import { Provider } from '@firebase/component';
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
import { MessagingInternalComponentName } from '@firebase/messaging-interop-types';
import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
import { isCloudWorkstation, pingServer } from '@firebase/util';
import {
isCloudWorkstation,
pingServer,
updateEmulatorBanner
} from '@firebase/util';

export const DEFAULT_REGION = 'us-central1';

Expand Down Expand Up @@ -182,6 +186,7 @@ export function connectFunctionsEmulator(
// Workaround to get cookies in Firebase Studio
if (useSsl) {
void pingServer(functionsInstance.emulatorOrigin);
updateEmulatorBanner('Functions', true);
}
}

Expand All @@ -195,6 +200,7 @@ export function httpsCallable<RequestData, ResponseData, StreamData = unknown>(
name: string,
options?: HttpsCallableOptions
): HttpsCallable<RequestData, ResponseData, StreamData> {
updateEmulatorBanner('Functions', functionsInstance.emulatorOrigin !== null);
const callable = (
data?: RequestData | null
): Promise<HttpsCallableResult> => {
Expand Down Expand Up @@ -225,6 +231,7 @@ export function httpsCallableFromURL<
url: string,
options?: HttpsCallableOptions
): HttpsCallable<RequestData, ResponseData, StreamData> {
updateEmulatorBanner('Functions', functionsInstance.emulatorOrigin !== null);
const callable = (
data?: RequestData | null
): Promise<HttpsCallableResult> => {
Expand Down
4 changes: 3 additions & 1 deletion packages/storage/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ import { STORAGE_TYPE } from './constants';
import {
EmulatorMockTokenOptions,
getModularInstance,
getDefaultEmulatorHostnameAndPort
getDefaultEmulatorHostnameAndPort,
updateEmulatorBanner
} from '@firebase/util';
import { StringFormat } from './implementation/string';

Expand Down Expand Up @@ -332,6 +333,7 @@ export function getStorage(
bucketUrl?: string
): FirebaseStorage {
app = getModularInstance(app);
updateEmulatorBanner('Storage', false);
const storageProvider: Provider<'storage'> = _getProvider(app, STORAGE_TYPE);
const storageInstance = storageProvider.getImmediate({
identifier: bucketUrl
Expand Down
5 changes: 4 additions & 1 deletion packages/storage/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ import {
createMockUserToken,
EmulatorMockTokenOptions,
isCloudWorkstation,
pingServer
pingServer,
updateEmulatorBanner
} from '@firebase/util';
import { Connection, ConnectionType } from './implementation/connection';

Expand Down Expand Up @@ -150,6 +151,7 @@ export function connectStorageEmulator(
// Workaround to get cookies in Firebase Studio
if (useSsl) {
void pingServer(`https://${storage.host}`);
updateEmulatorBanner('Storage', true);
}
storage._isUsingEmulator = true;
storage._protocol = useSsl ? 'https' : 'http';
Expand Down Expand Up @@ -324,6 +326,7 @@ export class FirebaseStorageImpl implements FirebaseStorage {
appCheckToken: string | null,
retry = true
): Request<O> {
updateEmulatorBanner('Service', this._isUsingEmulator);
if (!this._deleted) {
const request = makeRequest(
requestInfo,
Expand Down
Loading
Loading