Files
wallet/apps/extension/e2e/utils/wait-for-extension.ts
T
Hanzo AI 78b18797d5 init: extract wallet from lux/exchange monorepo
Copies apps/extension, apps/mobile and 10 pkgs (wallet, ui, config,
utilities, sessions, gating, notifications, analytics, eslint-config,
prices) into a standalone pnpm workspace.  Resolves merge conflict
markers in extension and mobile package.json files, strips build
artifacts (.wxt, .output, Pods).
2026-04-11 01:59:19 -07:00

57 lines
1.6 KiB
TypeScript

/* oxlint-disable typescript/no-explicit-any -- e2e test file */
import type { BrowserContext } from '@playwright/test'
import { sleep } from 'utilities/src/time/timing'
export async function waitForExtensionLoad(
context: BrowserContext,
options?: {
timeout?: number
waitForOnboarding?: boolean
},
// oxlint-disable-next-line typescript/no-explicit-any -- biome-parity: oxlint is stricter here
let onboardingPage: any
while (Date.now() - startTime < timeout) {
// Check all pages
const pages = context.pages()
for (const page of pages) {
const url = page.url()
if (url.startsWith('chrome-extension://')) {
extensionId = url.split('/')[2]
if (url.includes('onboarding')) {
onboardingPage = page
}
break
}
}
// Check service workers (MV3 extensions use service workers, not background pages)
if (!extensionId) {
const workers = context.serviceWorkers()
for (const worker of workers) {
const url = worker.url()
if (url.startsWith('chrome-extension://')) {
extensionId = url.split('/')[2]
break
}
}
}
// If we found the extension and we're waiting for onboarding, keep checking
if (extensionId && options?.waitForOnboarding && !onboardingPage) {
// Continue waiting for onboarding page
} else if (extensionId) {
// We have what we need
break
}
await sleep(100)
}
if (!extensionId) {
throw new Error(`Extension failed to load within ${timeout}ms`)
}
return { extensionId, onboardingPage }
}