Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to programatically click on chrome extension using playwright?

I have opened a webpage url using playwright and have a chrome extension installed in it using the below code.

You can ignore the page that i am doing to enable the developer mode in chrome so that my extension background script can run(somehow by default devMode is off)

const extensionPath = require('path').join(__dirname, 'audio-capture-extension');

  const context = await chromium.launchPersistentContext("", {
    headless: false,
    args:[
          `--load-extension=${extensionPath}`,
          `--disable-extensions-except=${extensionPath}`,
        ]
  });

  // const context = await browser.newContext();

  try {
  
    // Open new page
    const page = await context.newPage();
    await page.goto('chrome://extensions/')
    await page.waitForSelector('extensions-manager');
    const toggle = await page.$('#devMode')
    await page.waitForTimeout(1000)
    const isChecked = await toggle.getAttribute('aria-pressed');
    console.log(isChecked)
    if(isChecked == "false") {
        await page.click('#devMode');
    }
    await page.waitForTimeout(2000);
    const page2 = await context.newPage();
    await page2.goto('https://something.zoom.us/wc/98335327999/join?pwd=aWZEeklZUE1FR2lXaGhrTHZ65Jcwdz09');
    await page2.getByPlaceholder('Your Name').click();
    await page2.getByPlaceholder('Your Name').click();
    await page2.getByPlaceholder('Your Name').fill('Test User');
    await page2.getByRole('button', { name: 'Join' }).click();

    await page2.waitForTimeout(5000)

    /// waiting for 10 mins
    await page.waitForTimeout(1000*60*5); 
    await page.getByText('Joining Meeting...').click();

As you see that page2 has a zoom meeting link that i have joined using playwright. My requirement is after joining the meeting i want to activate the installed extension like clicking on extension icon by normal user. But with playwright i am not able to click on the extension menu that has this extension installed.

Any ideas how can I run this extension after loading my URL?

like image 816
Nishaant Sharma Avatar asked Aug 13 '26 06:08

Nishaant Sharma


1 Answers

By devtools using on the extension popup you can see the extension source - the link, like chrome-extension://sfasdfsdfasdferwegdfhjh/src/popup/popup.html. Where sfasdfsdfasdferwegdfhjh is the extension id. Next is matter of technique: open page with the extension and process.

P.S.

In without GUI script execution case (headless=True) use additional argument item within browser init - --headless=new for the extension working

like image 78
Dima Glin Avatar answered Aug 16 '26 19:08

Dima Glin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!