berstend / puppeteer-extra

💯 Teach puppeteer new tricks through plugins.
https://extra.community
MIT License
6.39k stars 738 forks source link

overridePermissions in puppeteer-extra with StealthPlugin() is not working... #214

Closed pxCaptcha closed 3 years ago

pxCaptcha commented 4 years ago

When I use overridePermissions my code is working in normal puppeteer or in puppeteer-extra without StealthPlugin() without any problem, but as soon as you add the StealthPlugin() its just not overriding anymore..

const context = browser.defaultBrowserContext();

context.overridePermissions("https://www.zalando.de/", ["geolocation", "notifications", "push", "midi", "camera", "microphone", "speaker", "device-info", "background-sync", "bluetooth", "persistent-storage", "ambient-light-sensor", "accelerometer", "gyroscope", "magnetometer", "clipboard", "accessibility-events", "clipboard-read", "clipboard-write", "payment-handler"]);

C2BB commented 3 years ago

Same problem here

Niek commented 3 years ago

The problem is that this is conflicting with the navigator.permissions evasion. To fix this, disable the evasion. Sample:

const pluginStealth = require('puppeteer-extra-plugin-stealth')()
pluginStealth.enabledEvasions.delete('navigator.permissions')
puppeteer.use(pluginStealth)
berstend commented 3 years ago

Theoretically the code should only affect e.g. await navigator.permissions.query({name:'notifications'})

We can also check if there's a better way to spoof this by using CDP methods, instead of JS patching.

Niek commented 3 years ago

There's Browser.setPermission(), but I'm not sure if/how that works in headless.

berstend commented 3 years ago

navigator.permissions has been rewritten (#429) in puppeteer-extra-plugin-stealth@2.7.5, kindly test if this is still an issue (closing for now).