-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extensions: Ability to click browser action buttons #2486
Comments
This would require some work in DevTools protocol, but should be doable. This is low-pri for us unless it proves to have high demand. |
High Demand Here! High Demand! |
@mcpine9 please upvote the issue itself - we sort by upvotes when figuring what to do next |
High demand. |
@aslushnikov is this still being considered? I would like to help test this feature when its in beta. If there's a workaround, I would also like to help QA it too. |
Clicking extension buttons should enable other testing scenarios, e.g. "tab capture" API requires user gesture: #2229 |
I would want this too please |
Right now the docs say "Test Chrome Extensions" as a use case. This may help assess demand for the feature as well. I got pretty far in before realizing I probably have to do some workaround like side-load and manually trigger my extension's code to do any kind of testing using puppeteer. |
Is there any workaround for this? Could someone suggest any solution for now ? Problem: I want to click a browser extension from Chromium toolbar. |
Our team has been using Puppeteer to test our extension (Accessibility Insights) for a while now, using a workaround for this issue where we open our popup page directly and pass the tab ID to associate with as a query param to the page for testing purposes. Unfortunately, this workaround doesn't work very well now that we're trying to follow best practices and switch our extension to use |
Working on a chrome extension testing automation too here and I must say it would make things 10 times more easier to have the possibility of clicking toolbar/extension icons too! |
Rising my thumb for this issue, as we'd love to be able to test the ABP popup through automation. Having an ETA could also help us prioritizing/organizing better, or look for alternatives. Thanks in advance for any sort of outcome. |
Found this on google; what is the best workaround currently to test toolbar button? What about context menu? |
any news? |
Assuming you have a background script and the required permissions specified in Note: Chrome type definitions do not include // find extension background target and load the page
const extBackgroundTarget = await browser.waitForTarget(t => t.type() === 'background_page')
const extBackgroundPage = await extBackgroundTarget.page()
// load a page from which to click browser action, make it the active tab
const someOtherPage = await browser.newPage()
await someOtherPage.goto('<some_url>')
await someOtherPage.bringToFront()
// evaluate chrome object in context of background page:
await extBackgroundPage.evaluate(() => {
chrome.tabs.query({ active: true }, tabs => {
chrome.browserAction.onClicked.dispatch(tabs[0]);
})
}) This works nicely to trigger whatever should happen when BrowserAction is clicked. I assume it should be possible also with |
Please build this. Much needed. |
I have an extension that its browserAction opens a popup, so the suggested solution didn't work for me using Puppeteer v2.1.1. (using Chromium v80).
Also I wanted not only to open the popup, but to also interact with elements inside it, so I had to patch puppeteer to make the target.page() available for me, and not return |
@itayadler this is awesome, thanks for the update and the hacky solution ♥ I hope they'll manage to properly provide the same feature with a less awkward dance soon! |
This would be vastly helpful for testing things like browser extensions. At OSlash, we're building a Chrome/Firefox extension that can immensely benefit from testing with Playwright. The one scenario that we'd love to cover is trigger the browser popup, which isn't possible today. |
Went on a hell of a journey to get this working. For those who are using manifest v3, you need to use service worker, target.worker(), and chrome.action instead: `// find extension service worker and get it // load a page from which to open the extension popup, make it the active tab await extWorker.evaluate(() => { |
see puppeteer/puppeteer#2486 for the details why we need this workaround
@haydnba we have a simple listener in our background script:
That would send a message back to that same tab's content script. But for some reason this doesn't trigger with your proposed solution, nor the MV3 version that @LeggoMahEggo showed. Anything specific that might need to be changed if we don't have a popup.html that would open by default and just the listener in the background context? |
Hello @andreasvirkus - if I'm right in understanding you are trying to do this in a MV3 context, it's not something I've tried yet but I would hope the only thing you are missing is providing the correct tab id to the // find extension service worker and get it
const extBackgroundTarget = await browser.waitForTarget(t => t.type() === 'service_worker');
const extWorker = await extBackgroundTarget.worker();
// load a page from which to click browser action, make it the active tab
const someOtherPage = await browser.newPage()
await someOtherPage.goto('<some_url>')
await someOtherPage.bringToFront()
// evaluate chrome object in context of service worker:
await extWorker.evaluate(() => {
chrome.tabs.query({ active: true }, tabs => {
chrome.action.onClicked.dispatch(tabs[0]);
})
}) |
UPDATE: The solution works when the DEPRECATED: // find extension service worker and get it
const extBackgroundTarget = await browser.waitForTarget(t => t.type() === 'service_worker');
const extWorker = await extBackgroundTarget.worker();
// load a page from which to open the extension popup, make it the active tab
const someOtherPage = await browser.newPage();
await someOtherPage.goto("https://www.google.com/", { waitUntil: ['domcontentloaded', "networkidle2"] });
await someOtherPage.bringToFront();
await extWorker.evaluate(() => {
chrome.action.openPopup(); // Add arguments as needed
}); And it doesn't work for me throwing an error when I execute
|
:) Is there a plan to support the devtools protocol? Which is important for the automated testing of extensions, thank you~ |
I am trying to open my Web Extension popup. Which I can do with: |
If anyone is reading this in 2024, and they're trying to get an extension with activeTab permission running make sure you do this
Note that --whitelisted-extension-id has been deprecated in favor of --allowlisted-extension-id |
We are relying on puppeteer to automate testing of our extension. I can automate most things except I cannot click the button that our extension adds to the browser's toolbar.
Could there be an API to interact with browser action buttons?
Something to the tune of
would be great.
This will allow us to fully automate testing of our extension workflow. Thanks!
The text was updated successfully, but these errors were encountered: