-
Notifications
You must be signed in to change notification settings - Fork 940
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
Changes from 22 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 cff6383
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk
XuechunHou 75646d9
added error handler to remote-config and performance modules on index…
XuechunHou e63607a
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk
XuechunHou f63a3e5
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
XuechunHou 4307ee5
issue #2393 fix for analytics module
XuechunHou 0843a6e
updateDoc()/deleteDoc() signature fix (#3147)
schmidt-sebastian 0c426c3
Transaction/WriteBatch signature fix (#3151)
schmidt-sebastian fd0c0a3
Take WriteStream offline when IndexedDB is unavailable (#2995)
schmidt-sebastian 9512b48
Do not build firestore lite in build because it breaks regular releas…
Feiyang1 b5c7b78
add pre script for build:release (#3161)
Feiyang1 e10388c
Add setLogLevel() (#3154)
schmidt-sebastian 3ac0fe3
Add DocumentReference (#3123)
schmidt-sebastian a377c68
issue #2393 fix for analytics module
XuechunHou 8b20b49
Merge branch 'issue-2393-analytics' of https://github.com/XuechunHou/…
XuechunHou 5bae362
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk
XuechunHou 1cac9fa
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk
XuechunHou 5db434a
added isSupported method to performance module
XuechunHou cdb438f
added isSupported method and indexedDB check in performance module
XuechunHou 25c19b8
added method signature to firebase/index.d.ts
XuechunHou d57d086
reverted unrelated files in remote-config
XuechunHou 9a15fa5
Create little-cycles-fold.md
XuechunHou 8efeefe
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
XuechunHou 0eb394f
removed isSupported method from performance
XuechunHou a6f0f2e
Merge branch 'issue-2393-performance' of https://github.com/firebase/…
XuechunHou 712b5d2
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
XuechunHou a3aeb6c
wrote tests for requiredApisAvailable
XuechunHou 1455b4e
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
XuechunHou 65d7b6d
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
XuechunHou dc23631
updated isRequiredApiAvailable tests, updated logTrace function to re…
XuechunHou faa05bd
added Promise existence check before every test of requiredApisAvailable
XuechunHou e012877
took validateIndexedDBOpenable outside of isRequiredApisAvailable
XuechunHou f558aa0
updated performance constructor test
XuechunHou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -109,11 +113,34 @@ export class Api { | |
); | ||
} | ||
|
||
requiredApisAvailable(): boolean { | ||
if (fetch && Promise && this.navigator && this.navigator.cookieEnabled) { | ||
async requiredApisAvailable(): Promise<boolean> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change looks good! |
||
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}` + | ||
'Wrap initialization of performance in performance.isSupported() ' + | ||
'to prevent initialization in unsupported environments' | ||
); | ||
return false; | ||
} | ||
return false; | ||
} | ||
|
||
setupObserver( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance is a monitoring sdk. It is easier for the users to initialize it in all environments, but performance will not start internally if all the apis it needs are not available.
Because of that, we probably do not need the isSupported function so the user can check before initializing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Analytics is in a similar situation but it throws if the environment conditions aren't met, on the assumption the developer might want to be alerted if they're not getting analytics data from a certain type of environment.
isSupported()
is a way to prevent initialization and avoid users having to see those errors. Maybe analytics could make some changes in the future?But for now, since Performance is designed to surface this through
console.info
which won't appear for most users, I guess we don't need a mechanism to suppress it. Also performance internal initialization can be blocked by an async check (unlike analytics) so it seems like all the checks and blocking can be handled without developers or users seeing anything.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the
isSupported
function