From f84617ad3ebdb3f0f4f7da5f139e904b35a0577f Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Fri, 17 Feb 2023 09:29:37 +0100 Subject: [PATCH] fix: find the svg owner element (#473) This PR fixes a bug where an svg owner is null if the target element is an svg element already. Drive-by: noticed missing dispose calls. --- src/PuppeteerRunnerExtension.ts | 8 +++++++- test/runner.test.ts | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/PuppeteerRunnerExtension.ts b/src/PuppeteerRunnerExtension.ts index 27aa9724..917271fe 100644 --- a/src/PuppeteerRunnerExtension.ts +++ b/src/PuppeteerRunnerExtension.ts @@ -545,14 +545,20 @@ async function scrollIntoViewIfNeeded( if (intersectionTarget) { await waitForInViewport(intersectionTarget, timeout); } + await intersectionTarget.dispose(); + if (intersectionTarget !== element) { + await element.dispose(); + } } async function getOwnerSVGElement( handle: ElementHandle ): Promise> { + // If there is no ownerSVGElement, the element must be the top-level SVG + // element itself. return await handle.evaluateHandle((element) => { /* c8 ignore start */ - return element.ownerSVGElement!; + return element.ownerSVGElement ?? (element as SVGSVGElement); /* c8 ignore stop */ }); } diff --git a/test/runner.test.ts b/test/runner.test.ts index b827e3ca..19334593 100644 --- a/test/runner.test.ts +++ b/test/runner.test.ts @@ -182,7 +182,7 @@ describe('Runner', () => { ); }); - it('should be able to replay click steps on SVG path elements', async () => { + it('should be able to replay click steps on SVG elements', async () => { const runner = await createRunner( { title: 'test', @@ -197,6 +197,12 @@ describe('Runner', () => { offsetX: 1, offsetY: 1, }, + { + type: StepType.Click, + selectors: ['svg'], + offsetX: 1, + offsetY: 1, + }, ], }, new PuppeteerRunnerExtension(browser, page)