File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ function applyDefaultOptions(optionsArg: BrowserOptions = {}): BrowserOptions {
63
63
type ExtensionProperties = {
64
64
chrome ?: Runtime ;
65
65
browser ?: Runtime ;
66
+ nw ?: unknown ;
66
67
} ;
67
68
type Runtime = {
68
69
runtime ?: {
@@ -85,7 +86,11 @@ function shouldShowBrowserExtensionError(): boolean {
85
86
const isDedicatedExtensionPage =
86
87
! ! runtimeId && WINDOW === WINDOW . top && extensionProtocols . some ( protocol => href . startsWith ( `${ protocol } //` ) ) ;
87
88
88
- return ! ! runtimeId && ! isDedicatedExtensionPage ;
89
+ // Running the SDK in NW.js, which appears like a browser extension but isn't, is also fine
90
+ // see: https://github.com/getsentry/sentry-javascript/issues/12668
91
+ const isNWjs = typeof windowWithMaybeExtension . nw !== 'undefined' ;
92
+
93
+ return ! ! runtimeId && ! isDedicatedExtensionPage && ! isNWjs ;
89
94
}
90
95
91
96
/**
Original file line number Diff line number Diff line change @@ -142,6 +142,7 @@ describe('init', () => {
142
142
afterEach ( ( ) => {
143
143
Object . defineProperty ( WINDOW , 'chrome' , { value : undefined , writable : true } ) ;
144
144
Object . defineProperty ( WINDOW , 'browser' , { value : undefined , writable : true } ) ;
145
+ Object . defineProperty ( WINDOW , 'nw' , { value : undefined , writable : true } ) ;
145
146
} ) ;
146
147
147
148
it ( 'logs a browser extension error if executed inside a Chrome extension' , ( ) => {
@@ -210,6 +211,18 @@ describe('init', () => {
210
211
consoleErrorSpy . mockRestore ( ) ;
211
212
} ) ;
212
213
214
+ it ( "doesn't log a browser extension error if executed inside an NW.js environment" , ( ) => {
215
+ const consoleErrorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
216
+
217
+ Object . defineProperty ( WINDOW , 'nw' , { value : { } } ) ;
218
+
219
+ init ( options ) ;
220
+
221
+ expect ( consoleErrorSpy ) . not . toHaveBeenCalled ( ) ;
222
+
223
+ consoleErrorSpy . mockRestore ( ) ;
224
+ } ) ;
225
+
213
226
it ( "doesn't return a client on initialization error" , ( ) => {
214
227
const consoleErrorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
215
228
You can’t perform that action at this time.
0 commit comments