Skip to content

Commit 007ff68

Browse files
authored
fix: catch error in getUrlParam() in DefaultUserProvider (#150)
1 parent a1afcfa commit 007ff68

File tree

1 file changed

+10
-4
lines changed
  • packages/experiment-browser/src/providers

1 file changed

+10
-4
lines changed

packages/experiment-browser/src/providers/default.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,20 @@ export class DefaultUserProvider implements ExperimentUserProvider {
119119

120120
private getUrlParam(): Record<string, string | string[]> {
121121
if (!this.globalScope) {
122-
return {};
122+
return undefined;
123123
}
124124

125125
const params: Record<string, string[]> = {};
126-
for (const [name, value] of new URL(this.globalScope?.location?.href)
127-
.searchParams) {
128-
params[name] = [...(params[name] ?? []), ...value.split(',')];
126+
127+
try {
128+
const url = new URL(this.globalScope.location.href);
129+
for (const [name, value] of url.searchParams) {
130+
params[name] = [...(params[name] ?? []), ...value.split(',')];
131+
}
132+
} catch (error) {
133+
return undefined;
129134
}
135+
130136
return Object.entries(params).reduce<Record<string, string | string[]>>(
131137
(acc, [name, value]) => {
132138
acc[name] = value.length == 1 ? value[0] : value;

0 commit comments

Comments
 (0)