berstend / puppeteer-extra

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

[Feature] There's no way to programatically set WebGL Renderer and Vendor #846

Open Pic2490 opened 8 months ago

Pic2490 commented 8 months ago

Feature request I think it would be essential if someone could change out the hardcoded values in WebGl Renderer and Vendor like the way one can .setUserAgent() on Start Up

GiveDaData commented 8 months ago

Not sure this is still maintained given no updates for a long time. You can manually change it.

find the file ...\node_modules\puppeteer-extra-plugin-stealth\evasions\webgl.vendor\index.js and modify it as you wish

// UNMASKED_VENDOR_WEBGL if (param === 37445) { return opts.vendor || 'Google Inc. (NVIDIA)' // default in headless: Google Inc. } // UNMASKED_RENDERER_WEBGL if (param === 37446) { return opts.renderer || 'ANGLE (NVIDIA, NVIDIA GeForce RTX 2080 TI Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6079)' // default in headless: Google SwiftShader }

Pic2490 commented 8 months ago

Not sure this is still maintained given no updates for a long time. You can manually change it.

find the file ...\node_modules\puppeteer-extra-plugin-stealth\evasions\webgl.vendor\index.js and modify it as you wish

// UNMASKED_VENDOR_WEBGL if (param === 37445) { return opts.vendor || 'Google Inc. (NVIDIA)' // default in headless: Google Inc. } // UNMASKED_RENDERER_WEBGL if (param === 37446) { return opts.renderer || 'ANGLE (NVIDIA, NVIDIA GeForce RTX 2080 TI Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6079)' // default in headless: Google SwiftShader }

Appreciate the swift response, I'm aware of changing it manually but do you know if there's a way to change it programmatically?

GiveDaData commented 8 months ago

Not sure this is still maintained given no updates for a long time. You can manually change it. find the file ...\node_modules\puppeteer-extra-plugin-stealth\evasions\webgl.vendor\index.js and modify it as you wish // UNMASKED_VENDOR_WEBGL if (param === 37445) { return opts.vendor || 'Google Inc. (NVIDIA)' // default in headless: Google Inc. } // UNMASKED_RENDERER_WEBGL if (param === 37446) { return opts.renderer || 'ANGLE (NVIDIA, NVIDIA GeForce RTX 2080 TI Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6079)' // default in headless: Google SwiftShader }

Appreciate the swift response, I'm aware of changing it manually but do you know if there's a way to change it programmatically?

Looking at the codes, I do not think there is such function

fxyoge commented 7 months ago

You can pass in opts if you new up the plugin yourself - I was able to do the following:

import pxe from "playwright-extra";
import stealth from "puppeteer-extra-plugin-stealth";
import WebGlVendorPlugin from "puppeteer-extra-plugin-stealth/evasions/webgl.vendor/index.js";
pxe.chromium.use(stealth({
  "enabledEvasions": new Set([
    // all from https://github.com/berstend/puppeteer-extra/blob/master/packages/puppeteer-extra-plugin-stealth/index.js#L82
    "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"
  ])
})).use(new WebGlVendorPlugin({
  vendor: "please no more captchas",
  renderer: "i'm begging you"
}));
arjunsharma1152 commented 7 months ago

@fxyoge Can we do it using Puppeteer only or how can we do it manually

marcusdiy commented 5 months ago

It certainly possibile, try something like this, of course it could be simpler.

const StealthPlugin = PuppeteerStealth(); StealthPlugin.enabledEvasions.delete('webgl.vendor'); let customGpu = require('puppeteer-extra-plugin-stealth/evasions/webgl.vendor')({ vendor: gpu.vendor, renderer: gpu.renderer }) Puppeteer.use(customGpu);

imaxs commented 2 months ago

const StealthPlugin = PuppeteerStealth(); StealthPlugin.enabledEvasions.delete('webgl.vendor'); let customGpu = require('puppeteer-extra-plugin-stealth/evasions/webgl.vendor')({ vendor: gpu.vendor, renderer: gpu.renderer }) Puppeteer.use(customGpu);

Does it even work at all?

imaxs commented 2 months ago

const StealthPlugin = PuppeteerStealth(); StealthPlugin.enabledEvasions.delete('webgl.vendor'); let customGpu = require('puppeteer-extra-plugin-stealth/evasions/webgl.vendor')({ vendor: gpu.vendor, renderer: gpu.renderer }) Puppeteer.use(customGpu);

I'm checking it out on https://browserleaks.com/webgl

And I see the values of vendor and renderer have NOT changed in any way

imaxs commented 2 months ago

I'm checking it out on https://browserleaks.com/webgl

Below is a method that works fine for me

await page.evaluateOnNewDocument(() => { WebGLRenderingContext.prototype.getParameter = function(origFn) { const paramMap = {}; paramMap[0x9245] = "ARM"; // UNMASKED_VENDOR_WEBGL paramMap[0x9246] = "Mali-G71"; // UNMASKED_RENDERER_WEBGL return function(parameter) { return paramMap[parameter] || origFn.call(this, parameter); }; }(WebGLRenderingContext.prototype.getParameter); WebGL2RenderingContext.prototype.getParameter = function(origFn) { const paramMap = {}; paramMap[0x9245] = "ARM"; // UNMASKED_VENDOR_WEBGL paramMap[0x9246] = "Mali-G71"; // UNMASKED_RENDERER_WEBGL return function(parameter) { return paramMap[parameter] || origFn.call(this, parameter); }; }(WebGL2RenderingContext.prototype.getParameter); });

vladtreny commented 2 months ago

^ This is easily detectable WebGLRenderingContext.prototype.getParameter.toString()

imaxs commented 2 months ago

^ This is easily detectable WebGLRenderingContext.prototype.getParameter.toString()

Well what solution can you offer to solve it?

dannyokec commented 1 month ago

^ This is easily detectable WebGLRenderingContext.prototype.getParameter.toString()

Well what solution can you offer to solve it?

No mind the guy joor. your solution was perfect. any suggestions for broken Image dimension ?