Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iframe.contentWindow evasion causes troubles for some ad systems #137

Closed
methyl opened this issue Jan 10, 2020 · 8 comments
Closed

iframe.contentWindow evasion causes troubles for some ad systems #137

methyl opened this issue Jan 10, 2020 · 8 comments
Labels
bug Something isn't working plugin: stealth ㊙️ Detection evasion related workaround-available

Comments

@methyl
Copy link

methyl commented Jan 10, 2020

Hello!

I've encountered a problem with iframe.contentWindow evasion. It seems to be breaking some of the websites that are displaying ads and I guess it's related to srcdoc attribute. With plugin enabled, the ad script instead of replacing iframe HTML content replaces whole page HTML.

You can see this being a case for eg. http://veganliftz.com/best-vegan-pre-workout.

Once I pluginStealth.enabledEvasions.delete('iframe.contentWindow') or enable adblocker, it starts to work again.

@methyl methyl changed the title iframe.contentWindow evasion causes troubles for Google Ads iframe.contentWindow evasion causes troubles for some ad systems Jan 10, 2020
@Niek
Copy link
Collaborator

Niek commented Jan 10, 2020

Probably related to puppeteer/puppeteer#1106

@berstend
Copy link
Owner

berstend commented Sep 2, 2020

As this is becoming the canonical ticket for this: The iframe.contentWindow evasion attempts to mitigate a nasty puppeteer bug but that comes at the expense of some sites (specifically ad-infested ones) breaking.

Most often you don't need this evasion and can just disable it if you experience issues:

// Remove specific evasion from enabled ones dynamically
const pluginStealth = require('puppeteer-extra-plugin-stealth')()
pluginStealth.enabledEvasions.delete('iframe.contentWindow')
puppeteer.use(pluginStealth)

Alternatively you could try using the adblocker plugin in tandem.

There's a chance I might be able to improve the evasion so it doesn't break sites anymore but it's not my highest priority right now.

@Phyks
Copy link

Phyks commented Sep 2, 2020

As per #137 (comment), discarding this evasion or using an adblocker for websites full of ads might not be an option. Sometimes you do need the ads (e.g. for correct placements / layouts).

Would you have some opinion on the patch proposed above? #202 (comment)

Thanks!

@Niek
Copy link
Collaborator

Niek commented Sep 16, 2020

I've probably solved this issue and rewrote the plugin a bit. Need to test a bit.

How does the check work? This way?
/Chrome/.test(fingerprint.userAgent) && fingerprint.iframeChrome === 'undefined'
Right?

You can see the existing tests in https://github.com/berstend/puppeteer-extra/blob/master/packages/puppeteer-extra-plugin-stealth/evasions/iframe.contentWindow/index.test.js

Run the tests locally: npx ava -v

@vladtreny
Copy link

vladtreny commented Sep 16, 2020

@Niek

The above one by @Phyks is correct. I would suggest to change it a bit

+++ if (key === 'document') {
+++ return iframe.contentDocument || iframe.contentWindow.document;
+++ }

iframe.contentWindow.document - This works for iFrames in other domains.

@Niek
Copy link
Collaborator

Niek commented Sep 16, 2020

PR @ #327, closing this

@raphaelpreston
Copy link

I might be confused by the threads, but has this been reopened? I'm running puppeteer-extra-plugin-stealth@2.6.5 and I'm still experiencing this issue (everything gets removed but the ads) on at least Best Buy. As before, deleting the iframe.contentWindow evasion fixes the problem.

@berstend
Copy link
Owner

berstend commented Nov 23, 2020

Pretty sure the issue isn't resolved altogether - the iframe.contentWindow evasion is a pretty dirty hack unfortunately. The proper way would be to fix this in the CDP driver (a chromium issue has been raised for that). :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working plugin: stealth ㊙️ Detection evasion related workaround-available
Projects
None yet
Development

No branches or pull requests

6 participants