|
| 1 | +import { readFileSync } from 'node:fs'; |
| 2 | +import { join } from 'node:path'; |
| 3 | +import { expect } from '@playwright/test'; |
| 4 | +import { sentryTest } from '../../../utils/fixtures'; |
| 5 | +import { envelopeRequestParser, waitForErrorRequest } from '../../../utils/helpers'; |
| 6 | + |
| 7 | +sentryTest('tags event if contains at least one third-party frame', async ({ getLocalTestUrl, page }) => { |
| 8 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 9 | + |
| 10 | + const errorEventPromise = waitForErrorRequest(page, e => { |
| 11 | + return e.exception?.values?.[0]?.value === 'I am a third party Error'; |
| 12 | + }); |
| 13 | + |
| 14 | + await page.route('**/thirdPartyScript.js', route => |
| 15 | + route.fulfill({ |
| 16 | + status: 200, |
| 17 | + body: readFileSync(join(__dirname, 'thirdPartyScript.js')), |
| 18 | + }), |
| 19 | + ); |
| 20 | + |
| 21 | + await page.goto(url); |
| 22 | + |
| 23 | + const errorEvent = envelopeRequestParser(await errorEventPromise); |
| 24 | + expect(errorEvent.tags?.third_party_code).toBe(true); |
| 25 | +}); |
| 26 | + |
| 27 | +/** |
| 28 | + * This test seems a bit more complicated than necessary but this is intentional: |
| 29 | + * When using `captureConsoleIntegration` in combination with `thirdPartyErrorFilterIntegration` |
| 30 | + * and `attachStacktrace: true`, the stack trace includes native code stack frames which previously broke |
| 31 | + * the third party error filtering logic. |
| 32 | + * |
| 33 | + * see https://github.com/getsentry/sentry-javascript/issues/17674 |
| 34 | + */ |
| 35 | +sentryTest( |
| 36 | + "doesn't tag event if doesn't contain third-party frames", |
| 37 | + async ({ getLocalTestUrl, page, browserName }) => { |
| 38 | + const url = await getLocalTestUrl({ testDir: __dirname }); |
| 39 | + |
| 40 | + const errorEventPromise = waitForErrorRequest(page, e => { |
| 41 | + return e.exception?.values?.[0]?.value === 'I am a first party Error'; |
| 42 | + }); |
| 43 | + |
| 44 | + await page.route('**/thirdPartyScript.js', route => |
| 45 | + route.fulfill({ |
| 46 | + status: 200, |
| 47 | + body: readFileSync(join(__dirname, 'thirdPartyScript.js')), |
| 48 | + }), |
| 49 | + ); |
| 50 | + |
| 51 | + await page.goto(url); |
| 52 | + |
| 53 | + await page.click('#errBtn'); |
| 54 | + |
| 55 | + const errorEvent = envelopeRequestParser(await errorEventPromise); |
| 56 | + |
| 57 | + expect(errorEvent.tags?.third_party_code).toBeUndefined(); |
| 58 | + |
| 59 | + // ensure the stack trace includes native code stack frames which previously broke |
| 60 | + // the third party error filtering logic |
| 61 | + if (browserName === 'chromium') { |
| 62 | + expect(errorEvent.exception?.values?.[0]?.stacktrace?.frames).toContainEqual({ |
| 63 | + filename: '<anonymous>', |
| 64 | + function: 'Array.forEach', |
| 65 | + in_app: true, |
| 66 | + }); |
| 67 | + } else if (browserName === 'webkit') { |
| 68 | + expect(errorEvent.exception?.values?.[0]?.stacktrace?.frames).toContainEqual({ |
| 69 | + filename: '[native code]', |
| 70 | + function: 'forEach', |
| 71 | + in_app: true, |
| 72 | + }); |
| 73 | + } |
| 74 | + }, |
| 75 | +); |
0 commit comments