Display all puppeteer plugins on a browser instance

Viewed 119

I have a service that accepts a puppeteer instance. I want to add a way of warning the developer if the browser instance is using the puppeteer-extra-plugin-stealth.

How can I easily check which plugins are enabled in a puppeteer browser instance?

function detectStealthPlugin(browserInstance) {
  if (browserInstance.containsStealthPlugin) { // this does not work obviously
    console.warn(" WARNING: you are useing puppeteer with stealth plugin.")
  }
}

I know you can use .plugins on the puppeteer object, but I cannot find out how to use it on the browser instance.

const puppeteer = require("puppeteer");
const isUsingStealthPlugin = (puppeteer) => {
  if (!puppeteer.plugins) {
    return false;
  }
  const pluginsUsed = puppeteer.plugins.map(p => p.constructor.name);
  return pluginsUsed.includes("StealthPlugin");
}

const browserInstance = await puppeteer.launch();
// this works ✅
isUsingStealthPlugin(puppeteer);
// THIS DOES NOT WORK ❌
isUsingStealthPlugin(browserInstance);
0 Answers
Related