Open AbraarArique opened 3 months ago
Have you been able to resolve this or make we enter the matter ?
just remove iframe.contentWindow
. This works:
import puppeteer from 'puppeteer-extra'
import pptr from 'puppeteer-extra'
const puppeteer = pptr.default
const evasions = new Set([
'chrome.app',
'chrome.csi',
'chrome.loadTimes',
'chrome.runtime',
'defaultArgs',
// 'iframe.contentWindow',
'media.codecs',
'navigator.hardwareConcurrency',
'navigator.languages',
'navigator.permissions',
'navigator.plugins',
'navigator.webdriver',
'sourceurl',
'user-agent-override',
'webgl.vendor',
'window.outerdimensions'
])
console.log('here')
puppeteer.use(StealthPlugin({enabledEvasions: evasions}))
const browser = await puppeteer.launch({
userDataDir: '_',
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
headless: false // <--- 1
})
const page = await browser.newPage()
// This try/catch is needed because this site will often exceed the default 30s timeout
try {
await page.goto(
'https://variety.com/2024/film/global/johnny-depp-modi-premiere-san-sebastian-film-festival-1236111999/', {timeout: 5_000}
)
} catch {}
const body = await page.evaluate(() => document.body.outerHTML.slice(0, 50))
console.log(body)
Describe the bug
When visiting certain pages (see full code example below),
puppeteer-extra-plugin-stealth
'siframe.contentWindow
evasion interacts with the site's JavaScript to cause the entire DOM/HTML to go blank or get deleted.No direct errors are thrown, which made it very difficult to pinpoint the cause of this issue when I first encountered it.
But after tweaking many Puppeteer settings, I found that
puppeteer-extra-plugin-stealth
is causing it.Then I was able to track it down to a specific evasion:
iframe.contentWindow
.Code Snippet
When I run this code, this error is thrown:
The reason why the TypeError occurs is because
document.body
is null.In fact, if you turn off headless and inspect visually, you'll first see the site load normally, but then everything on the page goes blank, and all HTML elements inside Chrome DevTools have disappeared.
But if you comment out
iframe.contentWindow
from the list of evasions, it works properly:For the particular site above, I also discovered that if you block all requests that include the path
pmc-plugins
in DevTools (this is a WordPress plugin), the above error doesn't occur.So I'm guessing that stealth plugin's
iframe.contentWindow
somehow messes up this site's internal JS scripts.This webpage also seems to contain
<iframe>
tags withsrcdoc
property, which may be relevant to this issue.I've also experienced this issue on other sites run by the same organization, such as https://www.billboard.com/
Versions