Skip to content

Commit 4be3dd3

Browse files
authored
fix: Make parseMetaMaskUrl platform agnostic (#2834)
`URL` in the browser does not populate the `hostname` property, additional logic is added to handle this.
1 parent 68761fb commit 4be3dd3

File tree

1 file changed

+9
-1
lines changed
  • packages/snaps-utils/src

1 file changed

+9
-1
lines changed

packages/snaps-utils/src/url.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@ export function parseMetaMaskUrl(str: string): {
2525
path: string;
2626
} {
2727
const url = new URL(str);
28-
const { hostname: authority, pathname: path, protocol } = url;
28+
const { protocol } = url;
2929
if (protocol !== 'metamask:') {
3030
throw new Error(
3131
`Unable to parse URL. Expected the protocol to be "metamask:", but received "${protocol}".`,
3232
);
3333
}
34+
35+
// The browser version of URL differs from the Node version so we rely on the href
36+
// property to grab the relevant parts of the url instead of hostname and pathname
37+
const [authority, ...pathElements] = url.href
38+
.replace('metamask://', '')
39+
.split('/');
40+
const path = `/${pathElements.join('/')}`;
41+
3442
switch (authority) {
3543
case 'client':
3644
assert(

0 commit comments

Comments
 (0)