-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(metamask): Add
getExtensionId
helper function
- Loading branch information
1 parent
9d56bf0
commit 1e41dcf
Showing
4 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { BrowserContext } from '@playwright/test' | ||
import { z } from 'zod' | ||
|
||
const Extension = z.object({ | ||
id: z.string(), | ||
name: z.string() | ||
}) | ||
|
||
const Extensions = z.array(Extension) | ||
|
||
export async function getExtensionId(context: BrowserContext, extensionName: string) { | ||
const page = await context.newPage() | ||
await page.goto('chrome://extensions') | ||
|
||
const unparsedExtensions = await page.evaluate('chrome.management.getAll()') | ||
|
||
const allExtensions = Extensions.parse(unparsedExtensions) | ||
const extension = allExtensions.find((extension) => extension.name.toLowerCase() === extensionName.toLowerCase()) | ||
|
||
if (!extension) { | ||
throw new Error( | ||
[ | ||
`[GetExtensionId] Extension with name ${extensionName} not found.`, | ||
`Available extensions: ${allExtensions.map((extension) => extension.name).join(', ')}` | ||
].join('\n') | ||
) | ||
} | ||
|
||
await page.close() | ||
|
||
return extension.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters