@@ -15,26 +15,34 @@ const RELOAD_DELAY = 1000
1515// Polling interval for finding extension page
1616const POLLING_INTERVAL = 500
1717
18- // MetaMask specific selectors
19- const METAMASK_SELECTORS = {
20- APP : '#app-content .app '
18+ const APP_SELECTORS = {
19+ METAMASK : '#app-content .app' ,
20+ PHANTOM : '#root '
2121}
2222
2323const sleep = ( ms : number ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) )
2424
2525/**
26- * Checks if a page is blank (no MetaMask app content)
26+ * Checks if a page is blank (no MetaMask or Phantom app content)
2727 */
28- async function isPageBlank ( page : Page ) : Promise < boolean > {
28+ async function isPageBlank ( page : Page , extensionPath : string ) : Promise < boolean > {
29+ const app = ( extensionPath : string ) => {
30+ if ( extensionPath . includes ( 'metamask' ) ) {
31+ return 'METAMASK'
32+ } else {
33+ return 'PHANTOM'
34+ }
35+ }
36+
2937 try {
30- // Check specifically for MetaMask app element
38+ // Check for specific app element
3139 const appElementCount = await page
32- . locator ( METAMASK_SELECTORS . APP )
40+ . locator ( APP_SELECTORS [ app ( extensionPath ) ] )
3341 . count ( )
3442 . catch ( ( ) => 0 )
3543
3644 if ( appElementCount === 0 ) {
37- console . log ( ' [WaitForExtensionOnLoadPage] MetaMask app element not found, page appears to be blank' )
45+ console . log ( ` [WaitForExtensionOnLoadPage] ${ app ( extensionPath ) } app element not found, page appears to be blank` )
3846 return true
3947 }
4048
@@ -50,11 +58,11 @@ async function isPageBlank(page: Page): Promise<boolean> {
5058/**
5159 * Attempts to fix a blank page by reloading
5260 */
53- async function fixBlankPage ( page : Page ) : Promise < boolean > {
61+ async function fixBlankPage ( page : Page , extensionPath : string ) : Promise < boolean > {
5462 for ( let attempt = 0 ; attempt < MAX_BLANK_PAGE_RETRIES ; attempt ++ ) {
5563 console . log ( `[WaitForExtensionOnLoadPage] Checking page state (attempt ${ attempt + 1 } /${ MAX_BLANK_PAGE_RETRIES } )` )
5664
57- const isBlank = await isPageBlank ( page )
65+ const isBlank = await isPageBlank ( page , extensionPath )
5866
5967 if ( isBlank ) {
6068 console . log ( '[WaitForExtensionOnLoadPage] Page is blank, reloading...' )
@@ -90,7 +98,7 @@ async function findExtensionPage(context: BrowserContext): Promise<Page | null>
9098/**
9199 * Waits for the extension page to load and ensures it's not blank or has errors
92100 */
93- export async function waitForExtensionOnLoadPage ( context : BrowserContext ) : Promise < Page > {
101+ export async function waitForExtensionOnLoadPage ( context : BrowserContext , extensionPath : string ) : Promise < Page > {
94102 let retries = 0
95103 console . log (
96104 `[WaitForExtensionOnLoadPage] Starting with timeout: ${ EXTENSION_LOAD_TIMEOUT } ms and max retries: ${ MAX_RETRIES } `
@@ -136,7 +144,7 @@ export async function waitForExtensionOnLoadPage(context: BrowserContext): Promi
136144
137145 // Now check if the page is blank or has errors and fix if needed
138146 console . log ( '[WaitForExtensionOnLoadPage] Checking if extension page is properly loaded...' )
139- const isFixed = await fixBlankPage ( extensionPage )
147+ const isFixed = await fixBlankPage ( extensionPage , extensionPath )
140148
141149 if ( isFixed ) {
142150 console . log ( '[WaitForExtensionOnLoadPage] Extension page is properly loaded and ready' )
0 commit comments