@@ -10,7 +10,12 @@ vi.mock('@sentry/react', () => ({
1010 setUser : sentrySetUserMock ,
1111} ) ) ;
1212
13- import { getFrontendSentryConfig , initFrontendSentry , setSentryUser } from './sentry' ;
13+ import {
14+ getFrontendSentryConfig ,
15+ initFrontendSentry ,
16+ setSentryUser ,
17+ shouldIgnoreThirdPartySafariAutofillError ,
18+ } from './sentry' ;
1419
1520describe ( 'frontend sentry config' , ( ) => {
1621 beforeEach ( ( ) => {
@@ -37,12 +42,13 @@ describe('frontend sentry config', () => {
3742 VITE_SENTRY_RELEASE : 'awork-forms@1.2.3' ,
3843 } ) ;
3944
40- expect ( sentryInitMock ) . toHaveBeenCalledWith ( {
45+ expect ( sentryInitMock ) . toHaveBeenCalledWith ( expect . objectContaining ( {
4146 dsn : 'https://key@o0.ingest.sentry.io/1' ,
4247 environment : 'staging' ,
4348 release : 'awork-forms@1.2.3' ,
4449 tracesSampleRate : 1.0 ,
45- } ) ;
50+ beforeSend : expect . any ( Function ) ,
51+ } ) ) ;
4652 } ) ;
4753
4854 it ( 'does not initialize sentry when dsn is blank' , async ( ) => {
@@ -75,12 +81,57 @@ describe('frontend sentry config', () => {
7581 VITE_SENTRY_RELEASE : 'vite-release' ,
7682 } ) ;
7783
78- expect ( sentryInitMock ) . toHaveBeenCalledWith ( {
84+ expect ( sentryInitMock ) . toHaveBeenCalledWith ( expect . objectContaining ( {
7985 dsn : 'https://runtime@o0.ingest.sentry.io/1' ,
8086 environment : 'runtime-env' ,
8187 release : 'runtime-release' ,
8288 tracesSampleRate : 1.0 ,
83- } ) ;
89+ beforeSend : expect . any ( Function ) ,
90+ } ) ) ;
91+ } ) ;
92+
93+ it ( 'ignores Safari autofill errors from masked third-party frames' , ( ) => {
94+ const event = {
95+ type : undefined ,
96+ exception : {
97+ values : [
98+ {
99+ type : 'TypeError' ,
100+ value : "null is not an object (evaluating 'autofillFieldData.autoCompleteType.includes')" ,
101+ stacktrace : {
102+ frames : [
103+ { filename : 'webkit-masked-url://hidden/' , function : 'setupOverlayOnField' } ,
104+ { filename : '[native code]' , function : 'Promise' } ,
105+ ] ,
106+ } ,
107+ } ,
108+ ] ,
109+ } ,
110+ } satisfies Parameters < typeof shouldIgnoreThirdPartySafariAutofillError > [ 0 ] ;
111+
112+ expect ( shouldIgnoreThirdPartySafariAutofillError ( event ) ) . toBe ( true ) ;
113+ } ) ;
114+
115+ it ( 'keeps application errors with real app frames' , ( ) => {
116+ const event = {
117+ type : undefined ,
118+ exception : {
119+ values : [
120+ {
121+ type : 'TypeError' ,
122+ value : "Cannot read properties of undefined (reading 'id')" ,
123+ stacktrace : {
124+ frames : [
125+ { filename : 'https://forms.awork.com/assets/index.js' , function : 'renderField' } ,
126+ { filename : 'https://forms.awork.com/assets/index.js' , function : 'handleSave' } ,
127+ ] ,
128+ } ,
129+ } ,
130+ ] ,
131+ } ,
132+ } satisfies Parameters < typeof shouldIgnoreThirdPartySafariAutofillError > [ 0 ] ;
133+
134+ expect ( shouldIgnoreThirdPartySafariAutofillError ( event ) ) . toBe ( false ) ;
84135 } ) ;
85136
86137 it ( 'sets sentry user with id, email, and workspace_id' , ( ) => {
0 commit comments