From ebeb4508ca0cc6cf54b4ba6154b2dca64f7c5835 Mon Sep 17 00:00:00 2001 From: Peter F Date: Wed, 18 Oct 2023 15:44:42 +0200 Subject: [PATCH] Fix localized Chrome's extension id (#928) * Fix localized Chrome's extension id * Improve id handling --------- Co-authored-by: Piotr Frankowski --- commands/playwright.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/commands/playwright.js b/commands/playwright.js index a474e8b5f..fa3e350f3 100644 --- a/commands/playwright.js +++ b/commands/playwright.js @@ -57,6 +57,11 @@ module.exports = { activeTabName() { return activeTabName; }, + async metamaskExtensionId() { + const metamaskExtensionData = (await module.exports.getExtensionsData()) + .metamask; + return metamaskExtensionData.id; + }, async setExpectInstance(expect) { expectInstance = expect; }, @@ -87,8 +92,7 @@ module.exports = { return true; }, async assignWindows() { - const metamaskExtensionData = (await module.exports.getExtensionsData()) - .metamask; + const metamaskExtensionId = await module.exports.metamaskExtensionId(); let pages = await browser.contexts()[0].pages(); for (const page of pages) { @@ -97,21 +101,21 @@ module.exports = { } else if ( page .url() - .includes(`chrome-extension://${metamaskExtensionData.id}/home.html`) + .includes(`chrome-extension://${metamaskExtensionId}/home.html`) ) { metamaskWindow = page; } else if ( page .url() .includes( - `chrome-extension://${metamaskExtensionData.id}/notification.html`, + `chrome-extension://${metamaskExtensionId}/notification.html`, ) ) { metamaskNotificationWindow = page; } else if ( page .url() - .includes(`chrome-extension://${metamaskExtensionData.id}/popup.html`) + .includes(`chrome-extension://${metamaskExtensionId}/popup.html`) ) { metamaskPopupWindow = page; } @@ -161,8 +165,7 @@ module.exports = { return true; }, async switchToMetamaskNotification() { - const metamaskExtensionData = (await module.exports.getExtensionsData()) - .metamask; + const metamaskExtensionId = await module.exports.metamaskExtensionId(); let pages = await browser.contexts()[0].pages(); for (const page of pages) { @@ -170,7 +173,7 @@ module.exports = { page .url() .includes( - `chrome-extension://${metamaskExtensionData.id}/notification.html`, + `chrome-extension://${metamaskExtensionId}/notification.html`, ) ) { metamaskNotificationWindow = page; @@ -337,15 +340,14 @@ module.exports = { } }, async waitUntilStable(page) { - const metamaskExtensionData = (await module.exports.getExtensionsData()) - .metamask; + const metamaskExtensionId = await module.exports.metamaskExtensionId(); if ( page && page .url() .includes( - `chrome-extension://${metamaskExtensionData.id}/notification.html`, + `chrome-extension://${metamaskExtensionId}/notification.html`, ) ) { await page.waitForLoadState('load'); @@ -477,7 +479,7 @@ module.exports = { const extensionId = ( await extensionData.locator('#extension-id').textContent() - ).replace('ID: ', ''); + ).split(': ')[1]; extensionsData[extensionName] = { version: extensionVersion,