File tree 4 files changed +27
-7
lines changed
4 files changed +27
-7
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @firebase/firebase " : patch
3
+ " @firebase/analytics " : patch
4
+ ---
5
+
6
+ Added Browser Extension check for Firebase Analytics. analytics.isSupported() will now return Promise<false > for extension environments.
Original file line number Diff line number Diff line change @@ -35,7 +35,8 @@ import { ERROR_FACTORY, AnalyticsError } from './src/errors';
35
35
import {
36
36
isIndexedDBAvailable ,
37
37
validateIndexedDBOpenable ,
38
- areCookiesEnabled
38
+ areCookiesEnabled ,
39
+ isBrowserExtension
39
40
} from '@firebase/util' ;
40
41
import { name , version } from './package.json' ;
41
42
@@ -109,19 +110,25 @@ declare module '@firebase/app-types' {
109
110
}
110
111
111
112
/**
112
- * this is a public static method provided to users that wraps three different checks:
113
+ * this is a public static method provided to users that wraps four different checks:
113
114
*
115
+ * 1. check if it's not a browser extension environment.
114
116
* 1. check if cookie is enabled in current browser.
115
- * 2. check if IndexedDB is supported by the browser environment.
116
- * 3. check if the current browser context is valid for using IndexedDB.
117
+ * 3. check if IndexedDB is supported by the browser environment.
118
+ * 4. check if the current browser context is valid for using IndexedDB.
119
+ *
117
120
*/
118
121
async function isSupported ( ) : Promise < boolean > {
122
+ if ( isBrowserExtension ( ) ) {
123
+ return false ;
124
+ }
119
125
if ( ! areCookiesEnabled ( ) ) {
120
126
return false ;
121
127
}
122
128
if ( ! isIndexedDBAvailable ( ) ) {
123
129
return false ;
124
130
}
131
+
125
132
try {
126
133
const isDBOpenable : boolean = await validateIndexedDBOpenable ( ) ;
127
134
return isDBOpenable ;
Original file line number Diff line number Diff line change @@ -25,7 +25,8 @@ export const enum AnalyticsError {
25
25
INTEROP_COMPONENT_REG_FAILED = 'interop-component-reg-failed' ,
26
26
INDEXED_DB_UNSUPPORTED = 'indexedDB-unsupported' ,
27
27
INVALID_INDEXED_DB_CONTEXT = 'invalid-indexedDB-context' ,
28
- COOKIES_NOT_ENABLED = 'cookies-not-enabled'
28
+ COOKIES_NOT_ENABLED = 'cookies-not-enabled' ,
29
+ INVALID_ANALYTICS_CONTEXT = 'invalid-analytics-context'
29
30
}
30
31
31
32
const ERRORS : ErrorMap < AnalyticsError > = {
@@ -50,7 +51,9 @@ const ERRORS: ErrorMap<AnalyticsError> = {
50
51
'Wrap initialization of analytics in analytics.isSupported() ' +
51
52
'to prevent initialization in unsupported environments' ,
52
53
[ AnalyticsError . COOKIES_NOT_ENABLED ] :
53
- 'Cookies are not enabled in this browser environment. Analytics requires cookies to be enabled.'
54
+ 'Cookies are not enabled in this browser environment. Analytics requires cookies to be enabled.' ,
55
+ [ AnalyticsError . INVALID_ANALYTICS_CONTEXT ] :
56
+ 'Firebase Analytics is not supported in browser extensions.'
54
57
} ;
55
58
56
59
interface ErrorParams {
Original file line number Diff line number Diff line change @@ -41,7 +41,8 @@ import { FirebaseInstallations } from '@firebase/installations-types';
41
41
import {
42
42
isIndexedDBAvailable ,
43
43
validateIndexedDBOpenable ,
44
- areCookiesEnabled
44
+ areCookiesEnabled ,
45
+ isBrowserExtension
45
46
} from '@firebase/util' ;
46
47
47
48
/**
@@ -122,6 +123,9 @@ export function factory(
122
123
app : FirebaseApp ,
123
124
installations : FirebaseInstallations
124
125
) : FirebaseAnalytics {
126
+ if ( isBrowserExtension ( ) ) {
127
+ throw ERROR_FACTORY . create ( AnalyticsError . INVALID_ANALYTICS_CONTEXT ) ;
128
+ }
125
129
if ( ! areCookiesEnabled ( ) ) {
126
130
throw ERROR_FACTORY . create ( AnalyticsError . COOKIES_NOT_ENABLED ) ;
127
131
}
You can’t perform that action at this time.
0 commit comments