From 74e50e4f6d45734f25fe5a4b7733bb3f88826145 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Tue, 25 Nov 2025 21:30:24 +0100 Subject: [PATCH] fix: ignore hash parts of URLs when finding DevTools --- src/DevtoolsUtils.ts | 8 ++++++++ tests/DevtoolsUtils.test.ts | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/DevtoolsUtils.ts b/src/DevtoolsUtils.ts index eb7ad365..e2629787 100644 --- a/src/DevtoolsUtils.ts +++ b/src/DevtoolsUtils.ts @@ -37,6 +37,7 @@ export function urlsEqual(url1: string, url2: string): boolean { * 1. We do not care about the protocol. * 2. We do not care about trailing slashes. * 3. We do not care about "www". + * 4. We ignore the hash parts. * * For example, if the user types "record a trace on foo.com", we would want to * match a tab in the connected Chrome instance that is showing "www.foo.com/" @@ -56,6 +57,13 @@ function normalizeUrl(url: string): string { result = result.slice(4); } + // We use target URLs to locate DevTools but those often do + // no include hash. + const hashIdx = result.lastIndexOf('#'); + if (hashIdx !== -1) { + result = result.slice(0, hashIdx); + } + // Remove trailing slash if (result.endsWith('/')) { result = result.slice(0, -1); diff --git a/tests/DevtoolsUtils.test.ts b/tests/DevtoolsUtils.test.ts index fd1569d5..947e5512 100644 --- a/tests/DevtoolsUtils.test.ts +++ b/tests/DevtoolsUtils.test.ts @@ -74,6 +74,17 @@ describe('urlsEqual', () => { false, ); }); + + it('ignores hash', () => { + assert.strictEqual( + urlsEqual('https://google.com/#', 'http://www.google.com'), + true, + ); + assert.strictEqual( + urlsEqual('https://google.com/#21', 'http://www.google.com#12'), + true, + ); + }); }); describe('mapIssueToMessageObject', () => {