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

Fix for calling functions on proxy (navigator.webdriver evasion) #130

Merged
merged 2 commits into from
Jan 7, 2020
Merged

Fix for calling functions on proxy (navigator.webdriver evasion) #130

merged 2 commits into from
Jan 7, 2020

Conversation

Niek
Copy link
Collaborator

@Niek Niek commented Jan 7, 2020

This fixes function calls on the navigator object, for example navigator.javaEnabled() which is called by Google Analytics.

Related Chromium bug: https://bugs.chromium.org/p/v8/issues/detail?id=5773

@Niek Niek changed the title Fix for calling functions on proxy - see Chromium bug 5773 Fix for calling functions on proxy (navigator.webdriver evasion) Jan 7, 2020
@berstend
Copy link
Owner

berstend commented Jan 7, 2020

Interesting. I wonder why that's necessary though - function calls are covered by the apply proxy trap? It shouldn't be necessary to bind the target context during Object.get() (which the get trap is taking care of).

I did a quick search if Reflect.get would take care of setting the this context to the target but it doesn't seem to be doing that. I'm a bit confused as of why this is necessary but if it fixes the issues you've mentioned we shall merge it in. :)

@berstend
Copy link
Owner

berstend commented Jan 7, 2020

Ah, well - it's a bug in Chromium so it doesn't need to make sense. 😄

@berstend
Copy link
Owner

berstend commented Jan 7, 2020

I've added a regression test so this won't happen again in the future:

test('stealth: regression: wont kill other navigator methods', async t => {
  const puppeteer = addExtra(vanillaPuppeteer).use(Plugin())
  const browser = await puppeteer.launch({ headless: true })
  const page = await browser.newPage()

  try {
    const data = await page.evaluate(() => navigator.javaEnabled())
    t.is(data, false)
  } catch (err) {
    t.is(err, undefined)
  }
})

d495042

@berstend berstend merged commit 6363573 into berstend:master Jan 7, 2020
@Niek
Copy link
Collaborator Author

Niek commented Jan 7, 2020

I agree it's weird, but apparently the apply trap is not called in case of native functions. Maybe it's fixed in a future Chromium release, so the regression test is a good idea.

@berstend
Copy link
Owner

berstend commented Jan 7, 2020

Good find regardless. :) I skimmed the rest of the evasions but this seems to be the only occurrence where this fix is required.

@berstend
Copy link
Owner

berstend commented Jan 7, 2020

Actually that's not true, found some other spots that had this issue and added the fix. 😅

@Niek
Copy link
Collaborator Author

Niek commented Jan 7, 2020

Oops... Didn't even think of checking other evasions, good catch!

@berstend
Copy link
Owner

berstend commented Jan 7, 2020

image

Released as puppeteer-extra-plugin-stealth@2.4.9 - thanks again @Niek! 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants