diff --git a/packages/core/src/browser/addEventListener.spec.ts b/packages/core/src/browser/addEventListener.spec.ts index 909f6f23a5..ce4295ec56 100644 --- a/packages/core/src/browser/addEventListener.spec.ts +++ b/packages/core/src/browser/addEventListener.spec.ts @@ -1,57 +1,9 @@ -import { createNewEvent } from '../../test/specHelper' import { stubZoneJs } from '../../test/stubZoneJs' -import type { RawTelemetryEvent } from '../domain/telemetry' -import { resetTelemetry, startFakeTelemetry } from '../domain/telemetry' import { noop } from '../tools/utils' -import { addEventListener, DOM_EVENT, resetUntrustedEventsCount } from './addEventListener' +import { addEventListener, DOM_EVENT } from './addEventListener' describe('addEventListener', () => { - describe('untrusted events reporting', () => { - let originalJasmine: typeof jasmine - let telemetryEvents: RawTelemetryEvent[] - let eventTarget: EventTarget - - beforeEach(() => { - eventTarget = document.createElement('div') - originalJasmine = window.jasmine - delete (window as any).jasmine - telemetryEvents = startFakeTelemetry() - }) - - afterEach(() => { - window.jasmine = originalJasmine - resetTelemetry() - resetUntrustedEventsCount() - }) - - it('sends a telemetry debug log when an untrusted event is dispatched', () => { - addEventListener(eventTarget, DOM_EVENT.CLICK, noop) - eventTarget.dispatchEvent(createNewEvent(DOM_EVENT.CLICK)) - - expect(telemetryEvents).toEqual([ - { - message: 'Untrusted event', - status: 'debug', - type: 'log', - event_type: 'click', - }, - ]) - }) - - it('only reports the first untrusted event of each type', () => { - addEventListener(eventTarget, DOM_EVENT.CLICK, noop) - addEventListener(eventTarget, DOM_EVENT.MOUSE_UP, noop) - - eventTarget.dispatchEvent(createNewEvent(DOM_EVENT.CLICK)) - eventTarget.dispatchEvent(createNewEvent(DOM_EVENT.CLICK)) - - eventTarget.dispatchEvent(createNewEvent(DOM_EVENT.MOUSE_UP)) - - expect(telemetryEvents.length).toBe(2) - }) - }) - describe('Zone.js support', () => { let zoneJsStub: ReturnType diff --git a/packages/core/src/browser/addEventListener.ts b/packages/core/src/browser/addEventListener.ts index df1fcf8d99..10de8e1983 100644 --- a/packages/core/src/browser/addEventListener.ts +++ b/packages/core/src/browser/addEventListener.ts @@ -1,6 +1,5 @@ import { monitor } from '../tools/monitor' import { getZoneJsOriginalValue } from '../tools/getZoneJsOriginalValue' -import { addTelemetryDebug } from '../domain/telemetry' export const enum DOM_EVENT { BEFORE_UNLOAD = 'beforeunload', @@ -81,13 +80,14 @@ export function addEventListeners( listener: (event: E) => void, { once, capture, passive }: AddEventListenerOptions = {} ) { - const wrappedListener = monitor((event: Event) => { - if (once) { - stop() - } - reportUntrustedEvent(event) - listener(event as E) - }) + const wrappedListener = monitor( + once + ? (event: Event) => { + stop() + listener(event as E) + } + : (listener as (event: Event) => void) + ) const options = passive ? { capture, passive } : capture @@ -103,20 +103,3 @@ export function addEventListeners( stop, } } - -const reportedUntrustedEventTypes = new Set() - -function reportUntrustedEvent(event: Event) { - const eventType = event.type - - if (event.isTrusted || (window as any).jasmine || reportedUntrustedEventTypes.has(eventType)) { - return - } - - reportedUntrustedEventTypes.add(eventType) - addTelemetryDebug('Untrusted event', { event_type: eventType }) -} - -export function resetUntrustedEventsCount() { - reportedUntrustedEventTypes.clear() -}