Skip to content

Issue 2393 - Add environment check to Performance Module #3424

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

Merged
merged 33 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5afb588
issue #2393, first fix on performance module and remote-config module
XuechunHou Jun 2, 2020
cff6383
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk
XuechunHou Jun 2, 2020
75646d9
added error handler to remote-config and performance modules on index…
XuechunHou Jun 2, 2020
e63607a
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk
XuechunHou Jun 2, 2020
f63a3e5
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
XuechunHou Jun 4, 2020
4307ee5
issue #2393 fix for analytics module
XuechunHou Jun 4, 2020
0843a6e
updateDoc()/deleteDoc() signature fix (#3147)
schmidt-sebastian Jun 2, 2020
0c426c3
Transaction/WriteBatch signature fix (#3151)
schmidt-sebastian Jun 2, 2020
fd0c0a3
Take WriteStream offline when IndexedDB is unavailable (#2995)
schmidt-sebastian Jun 2, 2020
9512b48
Do not build firestore lite in build because it breaks regular releas…
Feiyang1 Jun 3, 2020
b5c7b78
add pre script for build:release (#3161)
Feiyang1 Jun 3, 2020
e10388c
Add setLogLevel() (#3154)
schmidt-sebastian Jun 3, 2020
3ac0fe3
Add DocumentReference (#3123)
schmidt-sebastian Jun 3, 2020
a377c68
issue #2393 fix for analytics module
XuechunHou Jun 4, 2020
8b20b49
Merge branch 'issue-2393-analytics' of https://github.com/XuechunHou/…
XuechunHou Jun 4, 2020
5bae362
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk
XuechunHou Jun 26, 2020
1cac9fa
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk
XuechunHou Jul 16, 2020
5db434a
added isSupported method to performance module
XuechunHou Jul 16, 2020
cdb438f
added isSupported method and indexedDB check in performance module
XuechunHou Jul 16, 2020
25c19b8
added method signature to firebase/index.d.ts
XuechunHou Jul 16, 2020
d57d086
reverted unrelated files in remote-config
XuechunHou Jul 16, 2020
9a15fa5
Create little-cycles-fold.md
XuechunHou Jul 16, 2020
8efeefe
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
XuechunHou Jul 22, 2020
0eb394f
removed isSupported method from performance
XuechunHou Jul 22, 2020
a6f0f2e
Merge branch 'issue-2393-performance' of https://github.com/firebase/…
XuechunHou Jul 22, 2020
712b5d2
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
XuechunHou Jul 26, 2020
a3aeb6c
wrote tests for requiredApisAvailable
XuechunHou Jul 26, 2020
1455b4e
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
XuechunHou Aug 3, 2020
65d7b6d
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
XuechunHou Aug 3, 2020
dc23631
updated isRequiredApiAvailable tests, updated logTrace function to re…
XuechunHou Aug 4, 2020
faa05bd
added Promise existence check before every test of requiredApisAvailable
XuechunHou Aug 5, 2020
e012877
took validateIndexedDBOpenable outside of isRequiredApisAvailable
XuechunHou Aug 5, 2020
f558aa0
updated performance constructor test
XuechunHou Aug 6, 2020
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
6 changes: 6 additions & 0 deletions .changeset/little-cycles-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"firebase": minor
"@firebase/performance": minor
---

Issue 2393 - Add environment check to Performance Module
1 change: 0 additions & 1 deletion packages/performance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { ERROR_FACTORY, ErrorCode } from './src/utils/errors';
import { FirebasePerformance } from '@firebase/performance-types';
import { Component, ComponentType } from '@firebase/component';
import { FirebaseInstallations } from '@firebase/installations-types';

import { name, version } from './package.json';

const DEFAULT_ENTRY_NAME = '[DEFAULT]';
Expand Down
19 changes: 9 additions & 10 deletions packages/performance/src/controllers/perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@ import { getInitializationPromise } from '../services/initialization_service';
import { Api } from '../services/api_service';
import { FirebaseApp } from '@firebase/app-types';
import { FirebasePerformance } from '@firebase/performance-types';
import { consoleLogger } from '../utils/console_logger';
import { setupTransportService } from '../services/transport_service';

export class PerformanceController implements FirebasePerformance {
constructor(readonly app: FirebaseApp) {
if (Api.getInstance().requiredApisAvailable()) {
setupTransportService();
getInitializationPromise().then(setupOobResources, setupOobResources);
} else {
consoleLogger.info(
'Firebase Performance cannot start if browser does not support fetch and Promise or cookie is disabled.'
);
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Api.getInstance()
.requiredApisAvailable()
.then(isAvailable => {
if (isAvailable) {
setupTransportService();
getInitializationPromise().then(setupOobResources, setupOobResources);
}
});
}

trace(name: string): Trace {
Expand Down
31 changes: 27 additions & 4 deletions packages/performance/src/services/api_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
*/

import { ERROR_FACTORY, ErrorCode } from '../utils/errors';

import {
isIndexedDBAvailable,
validateIndexedDBOpenable
} from '@firebase/util';
import { consoleLogger } from '../utils/console_logger';
declare global {
interface Window {
PerformanceObserver: typeof PerformanceObserver;
Expand Down Expand Up @@ -109,11 +113,30 @@ export class Api {
);
}

requiredApisAvailable(): boolean {
if (fetch && Promise && this.navigator && this.navigator.cookieEnabled) {
async requiredApisAvailable(): Promise<boolean> {
Copy link
Contributor

Choose a reason for hiding this comment

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

The change looks good!
Can you please add a test for this function as it is not trivial anymore?

if (
!fetch ||
!Promise ||
!this.navigator ||
!this.navigator.cookieEnabled
) {
consoleLogger.info(
'Firebase Performance cannot start if browser does not support fetch and Promise or cookie is disabled.'
);
return false;
}

if (!isIndexedDBAvailable()) {
consoleLogger.info('IndexedDB is not supported by current browswer');
return false;
}
try {
await validateIndexedDBOpenable();
return true;
} catch (error) {
consoleLogger.info(`Environment doesn't support IndexedDB: ${error}`);
return false;
}
return false;
}

setupObserver(
Expand Down