When working with interactive window, is there a way to connect to crypto wallet like Phantom (Solana blockchain is needed)? I tried to find a button, click "connect wallet", but the chrome extension does not pop-up in an interactive window as it does in a normal browser.
-
https://docs.phantom.app/ – Luke Dupin Feb 20 '22 at 05:39
1 Answers
It seems like you already have puppeteer loading the Chrome extension, but if you have not. You will want to add the arguments in like this:
const browser = await puppeteer.launch({
headless: false,
devtools,
args: [
'--disable-extensions-except=./replacer-chrome-extension',
'--load-extension=./replacer-chrome-extension',
],
...(slowMo && { slowMo }),
});
Step 2:
Find the extension ID. You had the right idea to try to find look up the element, but the extension is a different DOM tree, so we want to load the extension into a new tab, by referencing the chrome-extension://
namespace to access those resources.
const extensionTarget = targets.find(target => target.type() === 'service_worker');
const partialExtensionUrl = extensionTarget._targetInfo.url || '';
const [, , extensionID] = partialExtensionUrl.split('/');
How to retrieve the extension id for a Manifest V2 Extension? How to retrieve the extension id for a Manifest V2 extension? const PAGE_TITLE = 'Text Replacer Extension'; const targets = await browser.targets(); extensionTarget = targets.find(({ _targetInfo }) => _targetInfo.title === PAGE_TITLE); const partialExtensionUrl = extensionTarget._targetInfo.url || '';
Once we figure out the id, we load the extension in a tab, and similarly to the application, we grab a page reference and return it.
const extPage = await browser.newPage();
const extensionUrl = `chrome-extension://${extensionId}/popup.html`;
await extPage.goto(extensionUrl, { waitUntil: 'load' });
return {
appPage,
browser,
extensionUrl,
extPage,
};
Source: https://tweak-extension.com/blog/complete-guide-test-chrome-extension-puppeteer/

- 61
- 1
- 5