Skip to content

Commit 4313489

Browse files
committed
AG-48914 Fix error on null event type in prevent-addEventListener
Squashed commit of the following: commit ebfbfd3 Author: Anatolii Khmarskii <a.khmarskii@adguard.com> Date: Fri Dec 19 17:58:09 2025 +0300 AG-48914 Fix error on null event type in prevent-addEventListener
1 parent 4075f9b commit 4313489

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
1717
- Support for React elements that don't respond to native clicks
1818
in `trusted-click-element` scriptlet [#542].
1919

20+
### Fixed
21+
22+
- Do not throw error on `null` event type in `prevent-addEventListener` scriptlet [#539].
23+
24+
[#539]: https://github.com/AdguardTeam/Scriptlets/issues/539
25+
2026
[#542]: https://github.com/AdguardTeam/Scriptlets/issues/542
2127

2228
## [v2.2.14] - 2025-12-16

src/helpers/add-event-listener-utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
*/
77
export const validateType = (type: unknown): boolean => {
88
// https://github.com/AdguardTeam/Scriptlets/issues/125
9-
return typeof type !== 'undefined';
9+
return typeof type !== 'undefined'
10+
// https://github.com/AdguardTeam/Scriptlets/issues/539
11+
&& type !== null;
1012
};
1113

1214
/**

tests/scriptlets/prevent-addEventListener.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,27 @@ test('should not prevent addEventListener if event is undefined', (assert) => {
8282
clearGlobalProps(testProp);
8383
});
8484

85+
test('should not throw error when event type is null', (assert) => {
86+
const TEST_EVENT_NAME = 'testEvent';
87+
runScriptlet(name, [TEST_EVENT_NAME]);
88+
89+
const testProp = 'test';
90+
window[testProp] = 'start';
91+
92+
// This should not throw an error
93+
assert.expect(2);
94+
try {
95+
document.addEventListener(null, () => {});
96+
window[testProp] = 'end';
97+
} catch (e) {
98+
assert.ok(false, `Should not throw error: ${e.message}`);
99+
}
100+
101+
assert.strictEqual(window[testProp], 'end', 'property should be changed to end');
102+
assert.strictEqual(window.hit, undefined, 'hit should not be fired');
103+
clearGlobalProps(testProp);
104+
});
105+
85106
test('does not allow to add event listener', (assert) => {
86107
const scriptletArgs = ['click', 'clicked'];
87108
runScriptlet(name, scriptletArgs);

0 commit comments

Comments
 (0)