2

This is my first time using puppeteer and I want to open a google chrome page and navigate to a chrome extension I have installed . I try to enable the chrome extension but when I run my script in headless:false mode the browser pops up without my extension .

My code :

//my extension path 
const StayFocusd = 'C:\\Users\\vasilis\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Extensions\\laankejkbhbdhmipfmgcngdelahlfoji\\1.6.0_0';

async function run(){
  
  //this is where I try to enable my extension 
  const browser = await puppeteer.launch({
    headless: false,
    ignoreDefaultArgs: [`--disable-extensions-except=${StayFocusd}`,"--enable-automation"],
  } 

  );
  
  const page = await browser.newPage();       
  sleep(3000);

  await browser.close();  
}


run();

So the extension does not load and I get no error or anything . I would appreciate your help

vasilis 123
  • 585
  • 1
  • 12
  • 26

1 Answers1

5

It is not enough to set --disable-extensions-except launch flag with your CRX path, you should also use --load-extension to actually load your extension in the opened browser instance.

You also seem to make a mistake using ignoreDefaultArgs where you should have used args (like this Chromium literally did the opposite of what you've expected).

Correct usage of puppeteer.launch:

const browser = await puppeteer.launch({
  headless: false,
  args: [
    `--disable-extensions-except=${StayFocusd}`, 
    `--load-extension=${StayFocusd}`,
    '--enable-automation'
  ]
}) 

You can make use of the official docs about Working with Chrome Extensions (link updated on: 2023-03-11).

theDavidBarton
  • 7,643
  • 4
  • 24
  • 51
  • I tested out with headless: "new" and it looks like above code will not work for it – rock stone Mar 10 '23 at 08:56
  • @rockstone actually the above solution works only with headful mode, extensions don't run in headless mode. ["new" is similar to headless: "true" in this context.](https://pptr.dev/api/puppeteer.browserlaunchargumentoptions.headless) – theDavidBarton Mar 10 '23 at 16:07
  • Actually we can use extensions with headless :"new" check this https://pptr.dev/guides/chrome-extensions but I am testing out on pixelscan it looks like location/timezone is still getting spoofed. No idea how to overcome it – rock stone Mar 10 '23 at 19:46
  • it can be, I haven't dived deeper into the new headless mode yet. their example should work with the latest version of pptr, in case it doesn't: it is worth raising a GitHub ticket for the maintainers. – theDavidBarton Mar 11 '23 at 10:53