Skip to content

Commit

Permalink
Fix localized Chrome's extension id (#928)
Browse files Browse the repository at this point in the history
* Fix localized Chrome's extension id

* Improve id handling

---------

Co-authored-by: Piotr Frankowski <[email protected]>
  • Loading branch information
piotrfrankowski and piotrfrankowski authored Oct 18, 2023
1 parent fc9b2aa commit ebeb450
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions commands/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -161,16 +165,15 @@ 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) {
if (
page
.url()
.includes(
`chrome-extension://${metamaskExtensionData.id}/notification.html`,
`chrome-extension://${metamaskExtensionId}/notification.html`,
)
) {
metamaskNotificationWindow = page;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -477,7 +479,7 @@ module.exports = {

const extensionId = (
await extensionData.locator('#extension-id').textContent()
).replace('ID: ', '');
).split(': ')[1];

extensionsData[extensionName] = {
version: extensionVersion,
Expand Down

0 comments on commit ebeb450

Please sign in to comment.