Puppeteer-extra: Stealth only works on newly created pages

Created on 5 Dec 2019  路  13Comments  路  Source: berstend/puppeteer-extra

I usually fetch the page like this:

const [ page ] = await browser.pages();

But this page will not be appropriately "stealthed" (webdriver is set, IIRC).

Instead you must do:

const page = await browser.newPage();

Ideally the initial page would also be "stealthed"; this was a subtle one that took me a while to find!

wontfix workaround-available

Most helpful comment

PS, here's a workaround (untested) until I implemented the fix:

const puppeteer = require("puppeteer-extra")

const StealthPlugin = require("puppeteer-extra-plugin-stealth")
const stealth = StealthPlugin()
puppeteer.use(stealth)

puppeteer.launch({ headless: false }).then(async browser => {
  // Add stealth to existing pages
  const pages = await browser.pages()
  for (const page in pages) {
    await stealth.onPageCreated(page)
  }

  await browser.close()
})

All 13 comments

Ah, I sometimes forget about that use-case 馃槃 If possible I'd recommend using new pages, as most pptr tooling works around the new-target-created events.

There's no technical reason for the stealth plugin not to work on existing pages, it's just that it currently only injects stuff when the onPageCreated event is fired. I just recently made a change to the recaptcha plugin to also enumerate potential open pages and inject it's payload there.

Given that we're now live for 2 years with half a million downloads and you're the first to notice I'm gonna assume most people create their pages as opposed to using existing ones 馃槃

Anyhow, will implement a fix so existing pages get stealthed as well.

I'm thinking about adding a new method to the base plugin: onPage (which behaves like onPageCreated + fired once for each existing page) to save some boilerplate in the plugins.

yea I think recommended way is to use

const page = await browser.newPage();

I don't see any reason to use

const [page] = await browser.newPage();

I think using the existing page saves a (very) small amount of RAM.

hmm then close that and spawn new tab. I think it is implication of chrome requiring at least one tab open so there is always a first tab?

But yeah, will implement a fix soon :) @njlr sorry for the debug session to figure this out 馃槃

PS, here's a workaround (untested) until I implemented the fix:

const puppeteer = require("puppeteer-extra")

const StealthPlugin = require("puppeteer-extra-plugin-stealth")
const stealth = StealthPlugin()
puppeteer.use(stealth)

puppeteer.launch({ headless: false }).then(async browser => {
  // Add stealth to existing pages
  const pages = await browser.pages()
  for (const page in pages) {
    await stealth.onPageCreated(page)
  }

  await browser.close()
})

@berstend If I use "puppeter extra plugin stearth" on the new page, it will be detected. If I don't use it, it won't be detected

@KrisWu-188 Any reproducible example you can share?

If the fix is not going to happen because of lack of people noticing the issue, then +1 because i faced it once too and took a very long time before figuring out what was wrong. You should fix it anyway because people will expect the plugin to work on all pages not just newly created ones.

took a very long time before figuring out what was wrong.

This should be immediately noticeable when turning on debug mode as suggested in the docs.

This is not affecting many people, otherwise there would be more activity or complaints in this issue. Given that there's a relatively clean workaround available and some much more pressing issues (playwright support, ongoing stealth stuff) this has a low priority.

Happy to merge in a documented and tested PR though.

Changing this to a wontfix - the demand for it is very low, a clean workaround available and I'm generally busy with more important things.

Was this page helpful?
0 / 5 - 0 ratings