Skip to content

Commit

Permalink
cherry-pick(#15224): fix: do not throw on removeListener without list…
Browse files Browse the repository at this point in the history
…ener (#15227)

SHA: b3c31f5
  • Loading branch information
mxschmitt committed Jun 29, 2022
1 parent 140f8e4 commit 389aa59
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/playwright-core/src/client/joiningEventEmitter.ts
Expand Up @@ -119,7 +119,8 @@ export class JoiningEventEmitter implements EventEmitter {
}

private _wrapper(listener: (...args: any[]) => void) {
return (listener as any)[wrapperListener];
// Fallback to original listener if not wrapped to ensure backwards compatibility Node.js's event emitter
return (listener as any)[wrapperListener] ?? listener;
}

private _original(wrapper: Function): Function {
Expand Down
4 changes: 4 additions & 0 deletions tests/page/page-event-pageerror.spec.ts
Expand Up @@ -128,3 +128,7 @@ it('should handle window', async ({ page, browserName, isElectron }) => {
]);
expect(error.message).toBe(browserName === 'chromium' ? 'Window' : '[object Window]');
});

it('should remove a listener of a non-existing event handler', async ({ page }) => {
page.removeListener('pageerror', () => {});
});

0 comments on commit 389aa59

Please sign in to comment.