Skip to content

Commit 52533d0

Browse files
authored
fix: ignore hash parts of URLs when finding DevTools (#608)
Closes #607
1 parent eb261fd commit 52533d0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/DevtoolsUtils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function urlsEqual(url1: string, url2: string): boolean {
3737
* 1. We do not care about the protocol.
3838
* 2. We do not care about trailing slashes.
3939
* 3. We do not care about "www".
40+
* 4. We ignore the hash parts.
4041
*
4142
* For example, if the user types "record a trace on foo.com", we would want to
4243
* match a tab in the connected Chrome instance that is showing "www.foo.com/"
@@ -56,6 +57,13 @@ function normalizeUrl(url: string): string {
5657
result = result.slice(4);
5758
}
5859

60+
// We use target URLs to locate DevTools but those often do
61+
// no include hash.
62+
const hashIdx = result.lastIndexOf('#');
63+
if (hashIdx !== -1) {
64+
result = result.slice(0, hashIdx);
65+
}
66+
5967
// Remove trailing slash
6068
if (result.endsWith('/')) {
6169
result = result.slice(0, -1);

tests/DevtoolsUtils.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ describe('urlsEqual', () => {
7474
false,
7575
);
7676
});
77+
78+
it('ignores hash', () => {
79+
assert.strictEqual(
80+
urlsEqual('https://google.com/#', 'http://www.google.com'),
81+
true,
82+
);
83+
assert.strictEqual(
84+
urlsEqual('https://google.com/#21', 'http://www.google.com#12'),
85+
true,
86+
);
87+
});
7788
});
7889

7990
describe('mapIssueToMessageObject', () => {

0 commit comments

Comments
 (0)