Skip to content

Commit 875a807

Browse files
committed
Revert "Add Emulator Overlay (#8977) (#9031)"
This reverts commit 8593fa0.
1 parent 939a2e7 commit 875a807

File tree

10 files changed

+15
-228
lines changed

10 files changed

+15
-228
lines changed

common/api-review/util.api.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,6 @@ export interface Subscribe<T> {
487487
// @public (undocumented)
488488
export type Unsubscribe = () => void;
489489

490-
// @public
491-
export function updateEmulatorBanner(name: string, isRunningEmulator: boolean): void;
492-
493490
// Warning: (ae-missing-release-tag) "validateArgCount" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
494491
//
495492
// @public

packages/auth/src/core/auth/emulator.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ import { Auth } from '../../model/public_types';
1818
import { AuthErrorCode } from '../errors';
1919
import { _assert } from '../util/assert';
2020
import { _castAuth } from './auth_impl';
21-
import {
22-
deepEqual,
23-
isCloudWorkstation,
24-
pingServer,
25-
updateEmulatorBanner
26-
} from '@firebase/util';
21+
import { deepEqual, isCloudWorkstation, pingServer } from '@firebase/util';
2722

2823
/**
2924
* Changes the {@link Auth} instance to communicate with the Firebase Auth Emulator, instead of production
@@ -102,12 +97,13 @@ export function connectAuthEmulator(
10297
authInternal.emulatorConfig = emulatorConfig;
10398
authInternal.settings.appVerificationDisabledForTesting = true;
10499

100+
if (!disableWarnings) {
101+
emitEmulatorWarning();
102+
}
103+
104+
// Workaround to get cookies in Firebase Studio
105105
if (isCloudWorkstation(host)) {
106-
updateEmulatorBanner('Auth', true);
107-
// Workaround to get cookies in Firebase Studio
108106
void pingServer(`${protocol}//${host}${portStr}`);
109-
} else if (!disableWarnings) {
110-
emitEmulatorWarning();
111107
}
112108
}
113109

packages/auth/src/platform_browser/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ import { browserSessionPersistence } from './persistence/session_storage';
3030
import { indexedDBLocalPersistence } from './persistence/indexed_db';
3131
import { browserPopupRedirectResolver } from './popup_redirect';
3232
import { Auth, User } from '../model/public_types';
33-
import {
34-
getDefaultEmulatorHost,
35-
getExperimentalSetting,
36-
updateEmulatorBanner
37-
} from '@firebase/util';
33+
import { getDefaultEmulatorHost, getExperimentalSetting } from '@firebase/util';
3834
import { _setExternalJSProvider } from './load_js';
3935
import { _createError } from '../core/util/assert';
4036
import { AuthErrorCode } from '../core/errors';
@@ -114,8 +110,6 @@ export function getAuth(app: FirebaseApp = getApp()): Auth {
114110
const authEmulatorHost = getDefaultEmulatorHost('auth');
115111
if (authEmulatorHost) {
116112
connectAuthEmulator(auth, `http://${authEmulatorHost}`);
117-
} else {
118-
updateEmulatorBanner('Auth', false);
119113
}
120114

121115
return auth;

packages/database/src/api/Database.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ import {
3131
EmulatorMockTokenOptions,
3232
getDefaultEmulatorHostnameAndPort,
3333
isCloudWorkstation,
34-
pingServer,
35-
updateEmulatorBanner
34+
pingServer
3635
} from '@firebase/util';
3736

3837
import { AppCheckTokenProvider } from '../core/AppCheckTokenProvider';
@@ -258,10 +257,6 @@ export class Database implements _FirebaseService {
258257
this.app.options['databaseAuthVariableOverride']
259258
);
260259
this._instanceStarted = true;
261-
updateEmulatorBanner(
262-
'Database',
263-
this._repo.repoInfo_.emulatorOptions !== null
264-
);
265260
}
266261
return this._repoInternal;
267262
}
@@ -398,7 +393,6 @@ export function connectDatabaseEmulator(
398393
// Workaround to get cookies in Firebase Studio
399394
if (isCloudWorkstation(host)) {
400395
void pingServer(host);
401-
updateEmulatorBanner('Database', true);
402396
}
403397

404398
// Modify the repo to apply emulator settings

packages/firestore/src/lite-api/database.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
EmulatorMockTokenOptions,
2929
getDefaultEmulatorHostnameAndPort,
3030
isCloudWorkstation,
31-
updateEmulatorBanner,
3231
pingServer
3332
} from '@firebase/util';
3433

@@ -143,7 +142,6 @@ export class Firestore implements FirestoreService {
143142

144143
_freezeSettings(): FirestoreSettingsImpl {
145144
this._settingsFrozen = true;
146-
updateEmulatorBanner('Firestore', this._settings.isUsingEmulator);
147145
return this._settings;
148146
}
149147

@@ -336,7 +334,9 @@ export function connectFirestoreEmulator(
336334
emulatorOptions: firestore._getEmulatorOptions()
337335
};
338336
const newHostSetting = `${host}:${port}`;
339-
337+
if (useSsl) {
338+
void pingServer(`https://${newHostSetting}`);
339+
}
340340
if (settings.host !== DEFAULT_HOST && settings.host !== newHostSetting) {
341341
logWarn(
342342
'Host has been set in both settings() and connectFirestoreEmulator(), emulator host ' +
@@ -357,11 +357,6 @@ export function connectFirestoreEmulator(
357357

358358
firestore._setSettings(newConfig);
359359

360-
if (useSsl) {
361-
void pingServer(`https://${newHostSetting}`);
362-
updateEmulatorBanner('Firestore', true);
363-
}
364-
365360
if (options.mockUserToken) {
366361
let token: string;
367362
let user: User;

packages/functions/src/api.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ import {
2929
} from './service';
3030
import {
3131
getModularInstance,
32-
getDefaultEmulatorHostnameAndPort,
33-
updateEmulatorBanner
32+
getDefaultEmulatorHostnameAndPort
3433
} from '@firebase/util';
3534

3635
export { FunctionsError } from './error';
@@ -48,7 +47,6 @@ export function getFunctions(
4847
app: FirebaseApp = getApp(),
4948
regionOrCustomDomain: string = DEFAULT_REGION
5049
): Functions {
51-
updateEmulatorBanner('Functions', false);
5250
// Dependencies
5351
const functionsProvider: Provider<'functions'> = _getProvider(
5452
getModularInstance(app),

packages/functions/src/service.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ import { Provider } from '@firebase/component';
3030
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
3131
import { MessagingInternalComponentName } from '@firebase/messaging-interop-types';
3232
import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
33-
import {
34-
isCloudWorkstation,
35-
pingServer,
36-
updateEmulatorBanner
37-
} from '@firebase/util';
33+
import { isCloudWorkstation, pingServer } from '@firebase/util';
3834

3935
export const DEFAULT_REGION = 'us-central1';
4036

@@ -186,7 +182,6 @@ export function connectFunctionsEmulator(
186182
// Workaround to get cookies in Firebase Studio
187183
if (useSsl) {
188184
void pingServer(functionsInstance.emulatorOrigin);
189-
updateEmulatorBanner('Functions', true);
190185
}
191186
}
192187

packages/storage/src/api.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ import { STORAGE_TYPE } from './constants';
5353
import {
5454
EmulatorMockTokenOptions,
5555
getModularInstance,
56-
getDefaultEmulatorHostnameAndPort,
57-
updateEmulatorBanner
56+
getDefaultEmulatorHostnameAndPort
5857
} from '@firebase/util';
5958
import { StringFormat } from './implementation/string';
6059

@@ -333,7 +332,6 @@ export function getStorage(
333332
bucketUrl?: string
334333
): FirebaseStorage {
335334
app = getModularInstance(app);
336-
updateEmulatorBanner('Storage', false);
337335
const storageProvider: Provider<'storage'> = _getProvider(app, STORAGE_TYPE);
338336
const storageInstance = storageProvider.getImmediate({
339337
identifier: bucketUrl

packages/storage/src/service.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ import {
4646
createMockUserToken,
4747
EmulatorMockTokenOptions,
4848
isCloudWorkstation,
49-
pingServer,
50-
updateEmulatorBanner
49+
pingServer
5150
} from '@firebase/util';
5251
import { Connection, ConnectionType } from './implementation/connection';
5352

@@ -151,7 +150,6 @@ export function connectStorageEmulator(
151150
// Workaround to get cookies in Firebase Studio
152151
if (useSsl) {
153152
void pingServer(`https://${storage.host}`);
154-
updateEmulatorBanner('Storage', true);
155153
}
156154
storage._isUsingEmulator = true;
157155
storage._protocol = useSsl ? 'https' : 'http';

packages/util/src/emulator.ts

Lines changed: 0 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
import { base64urlEncodeWithoutPadding } from './crypt';
19-
import { isCloudWorkstation } from './url';
2019

2120
// Firebase Auth tokens contain snake_case claims following the JWT standard / convention.
2221
/* eslint-disable camelcase */
@@ -141,180 +140,3 @@ export function createMockUserToken(
141140
signature
142141
].join('.');
143142
}
144-
145-
interface EmulatorStatusMap {
146-
[name: string]: boolean;
147-
}
148-
const emulatorStatus: EmulatorStatusMap = {};
149-
150-
interface EmulatorSummary {
151-
prod: string[];
152-
emulator: string[];
153-
}
154-
155-
// Checks whether any products are running on an emulator
156-
function getEmulatorSummary(): EmulatorSummary {
157-
const summary: EmulatorSummary = {
158-
prod: [],
159-
emulator: []
160-
};
161-
for (const key of Object.keys(emulatorStatus)) {
162-
if (emulatorStatus[key]) {
163-
summary.emulator.push(key);
164-
} else {
165-
summary.prod.push(key);
166-
}
167-
}
168-
return summary;
169-
}
170-
171-
function getOrCreateEl(id: string): { created: boolean; element: HTMLElement } {
172-
let parentDiv = document.getElementById(id);
173-
let created = false;
174-
if (!parentDiv) {
175-
parentDiv = document.createElement('div');
176-
parentDiv.setAttribute('id', id);
177-
created = true;
178-
}
179-
return { created, element: parentDiv };
180-
}
181-
182-
let previouslyDismissed = false;
183-
/**
184-
* Updates Emulator Banner. Primarily used for Firebase Studio
185-
* @param name
186-
* @param isRunningEmulator
187-
* @public
188-
*/
189-
export function updateEmulatorBanner(
190-
name: string,
191-
isRunningEmulator: boolean
192-
): void {
193-
if (
194-
typeof window === 'undefined' ||
195-
typeof document === 'undefined' ||
196-
!isCloudWorkstation(window.location.host) ||
197-
emulatorStatus[name] === isRunningEmulator ||
198-
emulatorStatus[name] || // If already set to use emulator, can't go back to prod.
199-
previouslyDismissed
200-
) {
201-
return;
202-
}
203-
204-
emulatorStatus[name] = isRunningEmulator;
205-
206-
function prefixedId(id: string): string {
207-
return `__firebase__banner__${id}`;
208-
}
209-
const bannerId = '__firebase__banner';
210-
const summary = getEmulatorSummary();
211-
const showError = summary.prod.length > 0;
212-
213-
function tearDown(): void {
214-
const element = document.getElementById(bannerId);
215-
if (element) {
216-
element.remove();
217-
}
218-
}
219-
220-
function setupBannerStyles(bannerEl: HTMLElement): void {
221-
bannerEl.style.display = 'flex';
222-
bannerEl.style.background = '#7faaf0';
223-
bannerEl.style.position = 'absolute';
224-
bannerEl.style.bottom = '5px';
225-
bannerEl.style.left = '5px';
226-
bannerEl.style.padding = '.5em';
227-
bannerEl.style.borderRadius = '5px';
228-
bannerEl.style.alignItems = 'center';
229-
}
230-
231-
function setupIconStyles(prependIcon: SVGElement, iconId: string): void {
232-
prependIcon.setAttribute('width', '24');
233-
prependIcon.setAttribute('id', iconId);
234-
prependIcon.setAttribute('height', '24');
235-
prependIcon.setAttribute('viewBox', '0 0 24 24');
236-
prependIcon.setAttribute('fill', 'none');
237-
prependIcon.style.marginLeft = '-6px';
238-
}
239-
240-
function setupCloseBtn(): HTMLSpanElement {
241-
const closeBtn = document.createElement('span');
242-
closeBtn.style.cursor = 'pointer';
243-
closeBtn.style.marginLeft = '16px';
244-
closeBtn.style.fontSize = '24px';
245-
closeBtn.innerHTML = ' &times;';
246-
closeBtn.onclick = () => {
247-
previouslyDismissed = true;
248-
tearDown();
249-
};
250-
return closeBtn;
251-
}
252-
253-
function setupLinkStyles(
254-
learnMoreLink: HTMLAnchorElement,
255-
learnMoreId: string
256-
): void {
257-
learnMoreLink.setAttribute('id', learnMoreId);
258-
learnMoreLink.innerText = 'Learn more';
259-
learnMoreLink.href =
260-
'https://firebase.google.com/docs/studio/preview-apps#preview-backend';
261-
learnMoreLink.setAttribute('target', '__blank');
262-
learnMoreLink.style.paddingLeft = '5px';
263-
learnMoreLink.style.textDecoration = 'underline';
264-
}
265-
266-
function setupDom(): void {
267-
const banner = getOrCreateEl(bannerId);
268-
const firebaseTextId = prefixedId('text');
269-
const firebaseText: HTMLSpanElement =
270-
document.getElementById(firebaseTextId) || document.createElement('span');
271-
const learnMoreId = prefixedId('learnmore');
272-
const learnMoreLink: HTMLAnchorElement =
273-
(document.getElementById(learnMoreId) as HTMLAnchorElement) ||
274-
document.createElement('a');
275-
const prependIconId = prefixedId('preprendIcon');
276-
const prependIcon: SVGElement =
277-
(document.getElementById(
278-
prependIconId
279-
) as HTMLOrSVGElement as SVGElement) ||
280-
document.createElementNS('http://www.w3.org/2000/svg', 'svg');
281-
if (banner.created) {
282-
// update styles
283-
const bannerEl = banner.element;
284-
setupBannerStyles(bannerEl);
285-
setupLinkStyles(learnMoreLink, learnMoreId);
286-
const closeBtn = setupCloseBtn();
287-
setupIconStyles(prependIcon, prependIconId);
288-
bannerEl.append(prependIcon, firebaseText, learnMoreLink, closeBtn);
289-
document.body.appendChild(bannerEl);
290-
}
291-
292-
if (showError) {
293-
firebaseText.innerText = `Preview backend disconnected.`;
294-
prependIcon.innerHTML = `<g clip-path="url(#clip0_6013_33858)">
295-
<path d="M4.8 17.6L12 5.6L19.2 17.6H4.8ZM6.91667 16.4H17.0833L12 7.93333L6.91667 16.4ZM12 15.6C12.1667 15.6 12.3056 15.5444 12.4167 15.4333C12.5389 15.3111 12.6 15.1667 12.6 15C12.6 14.8333 12.5389 14.6944 12.4167 14.5833C12.3056 14.4611 12.1667 14.4 12 14.4C11.8333 14.4 11.6889 14.4611 11.5667 14.5833C11.4556 14.6944 11.4 14.8333 11.4 15C11.4 15.1667 11.4556 15.3111 11.5667 15.4333C11.6889 15.5444 11.8333 15.6 12 15.6ZM11.4 13.6H12.6V10.4H11.4V13.6Z" fill="#212121"/>
296-
</g>
297-
<defs>
298-
<clipPath id="clip0_6013_33858">
299-
<rect width="24" height="24" fill="white"/>
300-
</clipPath>
301-
</defs>`;
302-
} else {
303-
prependIcon.innerHTML = `<g clip-path="url(#clip0_6083_34804)">
304-
<path d="M11.4 15.2H12.6V11.2H11.4V15.2ZM12 10C12.1667 10 12.3056 9.94444 12.4167 9.83333C12.5389 9.71111 12.6 9.56667 12.6 9.4C12.6 9.23333 12.5389 9.09444 12.4167 8.98333C12.3056 8.86111 12.1667 8.8 12 8.8C11.8333 8.8 11.6889 8.86111 11.5667 8.98333C11.4556 9.09444 11.4 9.23333 11.4 9.4C11.4 9.56667 11.4556 9.71111 11.5667 9.83333C11.6889 9.94444 11.8333 10 12 10ZM12 18.4C11.1222 18.4 10.2944 18.2333 9.51667 17.9C8.73889 17.5667 8.05556 17.1111 7.46667 16.5333C6.88889 15.9444 6.43333 15.2611 6.1 14.4833C5.76667 13.7056 5.6 12.8778 5.6 12C5.6 11.1111 5.76667 10.2833 6.1 9.51667C6.43333 8.73889 6.88889 8.06111 7.46667 7.48333C8.05556 6.89444 8.73889 6.43333 9.51667 6.1C10.2944 5.76667 11.1222 5.6 12 5.6C12.8889 5.6 13.7167 5.76667 14.4833 6.1C15.2611 6.43333 15.9389 6.89444 16.5167 7.48333C17.1056 8.06111 17.5667 8.73889 17.9 9.51667C18.2333 10.2833 18.4 11.1111 18.4 12C18.4 12.8778 18.2333 13.7056 17.9 14.4833C17.5667 15.2611 17.1056 15.9444 16.5167 16.5333C15.9389 17.1111 15.2611 17.5667 14.4833 17.9C13.7167 18.2333 12.8889 18.4 12 18.4ZM12 17.2C13.4444 17.2 14.6722 16.6944 15.6833 15.6833C16.6944 14.6722 17.2 13.4444 17.2 12C17.2 10.5556 16.6944 9.32778 15.6833 8.31667C14.6722 7.30555 13.4444 6.8 12 6.8C10.5556 6.8 9.32778 7.30555 8.31667 8.31667C7.30556 9.32778 6.8 10.5556 6.8 12C6.8 13.4444 7.30556 14.6722 8.31667 15.6833C9.32778 16.6944 10.5556 17.2 12 17.2Z" fill="#212121"/>
305-
</g>
306-
<defs>
307-
<clipPath id="clip0_6083_34804">
308-
<rect width="24" height="24" fill="white"/>
309-
</clipPath>
310-
</defs>`;
311-
firebaseText.innerText = 'Preview backend running in this workspace.';
312-
}
313-
firebaseText.setAttribute('id', firebaseTextId);
314-
}
315-
if (document.readyState === 'loading') {
316-
window.addEventListener('DOMContentLoaded', setupDom);
317-
} else {
318-
setupDom();
319-
}
320-
}

0 commit comments

Comments
 (0)