@@ -135,14 +135,16 @@ describe('init', () => {
135
135
new MockIntegration ( 'MockIntegration 0.2' ) ,
136
136
] ;
137
137
138
+ const originalLocation = WINDOW . location || { } ;
139
+
138
140
const options = getDefaultBrowserOptions ( { dsn : PUBLIC_DSN , defaultIntegrations : DEFAULT_INTEGRATIONS } ) ;
139
141
140
142
afterEach ( ( ) => {
141
143
Object . defineProperty ( WINDOW , 'chrome' , { value : undefined , writable : true } ) ;
142
144
Object . defineProperty ( WINDOW , 'browser' , { value : undefined , writable : true } ) ;
143
145
} ) ;
144
146
145
- it ( 'should log a browser extension error if executed inside a Chrome extension' , ( ) => {
147
+ it ( 'logs a browser extension error if executed inside a Chrome extension' , ( ) => {
146
148
const consoleErrorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
147
149
148
150
Object . defineProperty ( WINDOW , 'chrome' , {
@@ -160,7 +162,7 @@ describe('init', () => {
160
162
consoleErrorSpy . mockRestore ( ) ;
161
163
} ) ;
162
164
163
- it ( 'should log a browser extension error if executed inside a Firefox/Safari extension' , ( ) => {
165
+ it ( 'logs a browser extension error if executed inside a Firefox/Safari extension' , ( ) => {
164
166
const consoleErrorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
165
167
166
168
Object . defineProperty ( WINDOW , 'browser' , { value : { runtime : { id : 'mock-extension-id' } } , writable : true } ) ;
@@ -175,7 +177,30 @@ describe('init', () => {
175
177
consoleErrorSpy . mockRestore ( ) ;
176
178
} ) ;
177
179
178
- it ( 'should not log a browser extension error if executed inside regular browser environment' , ( ) => {
180
+ it . each ( [ 'chrome-extension' , 'moz-extension' , 'ms-browser-extension' ] ) (
181
+ "doesn't log a browser extension error if executed inside an extension running in a dedicated page (%s)" ,
182
+ extensionProtocol => {
183
+ const consoleErrorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
184
+
185
+ // @ts -expect-error - this is a hack to simulate a dedicated page in a browser extension
186
+ delete WINDOW . location ;
187
+ // @ts -expect-error - this is a hack to simulate a dedicated page in a browser extension
188
+ WINDOW . location = {
189
+ href : `${ extensionProtocol } ://mock-extension-id/dedicated-page.html` ,
190
+ } ;
191
+
192
+ Object . defineProperty ( WINDOW , 'browser' , { value : { runtime : { id : 'mock-extension-id' } } , writable : true } ) ;
193
+
194
+ init ( options ) ;
195
+
196
+ expect ( consoleErrorSpy ) . toBeCalledTimes ( 0 ) ;
197
+
198
+ consoleErrorSpy . mockRestore ( ) ;
199
+ WINDOW . location = originalLocation ;
200
+ } ,
201
+ ) ;
202
+
203
+ it ( "doesn't log a browser extension error if executed inside regular browser environment" , ( ) => {
179
204
const consoleErrorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
180
205
181
206
init ( options ) ;
0 commit comments