Skip to content

Commit 362208e

Browse files
feat: Add URLSearchParams as a default endowment (#3047)
Add `URLSearchParams` as a default global to allow for easy modification of query strings for API calls. This was already somewhat available through `URL.searchParams`. Closes #3044
1 parent cc563af commit 362208e

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

packages/snaps-execution-environments/src/common/endowments/commonEndowmentFactory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const commonEndowments: CommonEndowmentSpecification[] = [
4949
{ endowment: Uint16Array, name: 'Uint16Array' },
5050
{ endowment: Uint32Array, name: 'Uint32Array' },
5151
{ endowment: URL, name: 'URL' },
52+
{ endowment: URLSearchParams, name: 'URLSearchParams' },
5253
{ endowment: WebAssembly, name: 'WebAssembly' },
5354
];
5455

packages/snaps-execution-environments/src/common/endowments/endowments.test.browser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ describe('endowments', () => {
9292
endowments: { URL },
9393
factory: () => new URL('https://metamask.io/snaps/'),
9494
},
95+
URLSearchParams: {
96+
endowments: { URLSearchParams },
97+
factory: () => new URLSearchParams('https://metamask.io/snaps?foo=bar'),
98+
},
9599
Int8Array: {
96100
endowments: { Int8Array },
97101
factory: () => new Int8Array(),
@@ -384,6 +388,7 @@ describe('endowments', () => {
384388
{ factory: expect.any(Function), names: ['Uint16Array'] },
385389
{ factory: expect.any(Function), names: ['Uint32Array'] },
386390
{ factory: expect.any(Function), names: ['URL'] },
391+
{ factory: expect.any(Function), names: ['URLSearchParams'] },
387392
{ factory: expect.any(Function), names: ['WebAssembly'] },
388393
]);
389394
});

packages/snaps-simulation/src/methods/specifications.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ describe('getEndowments', () => {
347347
"TextDecoder",
348348
"TextEncoder",
349349
"URL",
350+
"URLSearchParams",
350351
"setInterval",
351352
"clearInterval",
352353
"Int8Array",

packages/snaps-utils/src/default-endowments.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const DEFAULT_ENDOWMENTS: readonly string[] = Object.freeze([
1515
'TextDecoder',
1616
'TextEncoder',
1717
'URL',
18+
'URLSearchParams',
1819
'setInterval',
1920
'clearInterval',
2021
'Int8Array',

0 commit comments

Comments
 (0)