Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
maximgeerinck committed Jun 8, 2023
1 parent 8fea081 commit f796d90
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
3 changes: 3 additions & 0 deletions commands/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ const metamask = {
async goToImportToken() {
await module.exports.goTo(extensionImportTokenUrl);
},
clearExtensionData: async () => {
await playwright.clearExtensionData(PROVIDER);
},
async getExtensionDetails() {
extensionInitialUrl = await playwright.windows(PROVIDER).url();
extensionId = extensionInitialUrl.match('//(.*?)/')[1];
Expand Down
3 changes: 3 additions & 0 deletions commands/phantom.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ module.exports = {
goToImportToken: async () => {
await module.exports.goTo(extensionImportTokenUrl);
},
clearExtensionData: async () => {
await playwright.clearExtensionData(PROVIDER);
},
getExtensionDetails: async () => {
extensionInitialUrl = await playwright.windows(PROVIDER).url();
extensionId = extensionInitialUrl.match('//(.*?)/')[1];
Expand Down
71 changes: 65 additions & 6 deletions commands/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ module.exports = {
const pages = await pagesResponse.json();

extensions = pages
.filter(
page =>
page.url.startsWith('chrome-extension://') &&
!page.url.endsWith('/_generated_background_page.html'), // cypress
)
.filter(page => page.url.startsWith('chrome-extension://'))
.map(extension => {
const matches = extension.url.match(/chrome-extension:\/\/(.*)\/.*/);
return {
Expand All @@ -76,12 +72,69 @@ module.exports = {
? 'phantom'
: extension.title.toLowerCase(),
id: matches[1],
welcomeUrl:
extension.title === 'Phantom Wallet'
? extension.url.replace('popup.html', 'onboarding.html')
: extension.url,
};
})
.reduce((prev, curr) => ({ ...prev, [curr.name]: curr }), {});

return browser.isConnected();
},
clearExtensionData: async provider => {
try {
// if (!mainWindow) {
// const newPage = await browser.contexts()[0].newPage();
// mainWindow = newPage;
// }

// await module.exports.switchToWindow(provider);
await module.exports.windows(provider).evaluate(async () => {
await new Promise((resolve, reject) => {
return chrome.storage.local.clear(() => {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
} else {
resolve(true);
}
});
});

await new Promise((resolve, reject) => {
return chrome.storage.sync.clear(() => {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
} else {
resolve(true);
}
});
});
// chrome.runtime.reload(); // closes the popup
});
// await mainWindow.waitForTimeout(1000);
// await module.exports.windows(provider).waitForTimeout(1000);
await module.exports.windows(provider).reload();
// return module.exports.windows(provider);
// await mainWindow.waitForTimeout(1000);
// const newPagePromise = new Promise(resolve =>
// browser.contexts()[0].once('page', resolve),
// );
// await mainWindow.evaluate(async extensionWelcomeUrl => {
// window.open(extensionWelcomeUrl, '_blank').focus();
// }, extensions[provider].welcomeUrl);

// await new Promise(resolve => setTimeout(resolve, 20000));
// pageWindows[provider] = await newPagePromise;
// pageWindows[provider] = newPage;
// await module.exports.assignActiveTabName(provider);
// await module.exports.windows(provider).reload();
// await module.exports.waitUntilStable();
// return module.exports.windows(provider);
} catch (ex) {
console.log(`[${provider}]: ${ex.message}`);
}
},
async clear() {
browser = null;
return true;
Expand All @@ -100,6 +153,12 @@ module.exports = {
pageWindows[provider] = page;
}
}

// if (!mainWindow) {
// const newPage = await browser.contexts()[0].newPage();
// mainWindow = newPage;
// }

return true;
},
async assignActiveTabName(tabName) {
Expand Down Expand Up @@ -154,7 +213,7 @@ module.exports = {

await module.exports.windows(provider).bringToFront();
await module.exports.assignActiveTabName(provider);
return true;
return module.exports.windows(provider);
},
async switchToNotificationWindow(provider) {
await notificationWindows[provider].bringToFront();
Expand Down

0 comments on commit f796d90

Please sign in to comment.