Skip to content

Commit

Permalink
fix: fix webGL error
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-void0 committed Jan 17, 2024
1 parent 9d82b1b commit 876f575
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
13 changes: 8 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,18 @@ const instance = new FakeFingerPrint({
// audio: {
// strength: 100,
// },
timezone: {
zone: 'America/NewYork',
locale: 'en-US',
offset: -5,
// timezone: {
// zone: 'America/New_York',
// locale: 'en-US',
// offset: -5,
// },
webGL: {
driver: 'ANGLE (NVIDIA GeForce GTX 1050 Ti Direct3D11 vs_5_0 ps_5_0)',
},
},
report: (arg) => {
console.log('key:', arg)
},
})

instance.open(['timezone'])
instance.open(['webGL'])
32 changes: 26 additions & 6 deletions src/lib/webGL.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import { type AbstractBaseFunc, Base } from './base'

export interface WebGLOpts {
param: ReturnType<WebGLRenderingContext['getParameter']>
/*
eg:
'ANGLE (NVIDIA GeForce GTX 1050 Ti Direct3D11 vs_5_0 ps_5_0)',
'ANGLE (Intel(R) HD Graphics 630 Direct3D11 vs_5_0 ps_5_0)',
'ANGLE (Intel(R) UHD Graphics 620 Direct3D11 vs_5_0 ps_5_0)',
'ANGLE (AMD Radeon(TM) R5 Graphics Direct3D11 vs_5_0 ps_5_0)',
'ANGLE (NVIDIA GeForce RTX 2070 SUPER Direct3D11 vs_5_0 ps_5_0)',
'ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E9B) Direct3D11 vs_5_0 ps_5_0, D3D11)',
'Mesa DRI Intel(R) HD Graphics 5500 (Broadwell GT2)',
'Mesa DRI Intel(R) UHD Graphics 630 (Coffeelake 3x8 GT2)',
'Mesa DRI Intel(R) Iris(R) Plus Graphics 640 (Kaby Lake GT3e)',
'AMD Radeon Pro 5300M OpenGL Engine',
'Intel(R) Iris(R) Plus Graphics OpenGL Engine',
*/
driver: string
}

export type WebGLReport = {
type: 'webGL'
key: 'WebGLRenderingContext.getParameter' | 'WebGL2RenderingContext.getParameter'
key: 'WebGLRenderingContext.renderDriver' | 'WebGL2RenderingContext.renderDriver'
}

export class WebGLHandle extends Base<WebGLOpts, WebGLReport> implements AbstractBaseFunc {
Expand All @@ -25,19 +39,25 @@ export class WebGLHandle extends Base<WebGLOpts, WebGLReport> implements Abstrac
this: WebGLRenderingContext,
...args: Parameters<WebGLRenderingContext['getParameter']>
) {
self.report({ type: 'webGL', key: 'WebGLRenderingContext.getParameter' })
const debugEx = this.getExtension('WEBGL_debug_renderer_info')
if (args[0] === debugEx?.UNMASKED_RENDERER_WEBGL) return self.config?.param
/* Renderer string of the graphics driver. */
if (args[0] === debugEx?.UNMASKED_RENDERER_WEBGL) {
self.report({ type: 'webGL', key: 'WebGLRenderingContext.renderDriver' })
return self.config?.driver
}
return self.oriWebGLGetParameter.apply(this, args)
}

WebGL2RenderingContext.prototype.getParameter = function (
this: WebGL2RenderingContext,
...args: Parameters<WebGL2RenderingContext['getParameter']>
) {
self.report({ type: 'webGL', key: 'WebGL2RenderingContext.getParameter' })
const debugEx = this.getExtension('WEBGL_debug_renderer_info')
if (args[0] === debugEx?.UNMASKED_RENDERER_WEBGL) return self.config?.param
/* Renderer string of the graphics driver. */
if (args[0] === debugEx?.UNMASKED_RENDERER_WEBGL){

Check warning on line 57 in src/lib/webGL.ts

View workflow job for this annotation

GitHub Actions / Lint: node-LTS, ubuntu-latest

Insert `·`
self.report({ type: 'webGL', key: 'WebGL2RenderingContext.renderDriver' })
return self.config?.driver
}
return self.oriWebGL2GetParameter.apply(this, args)
}
}
Expand Down

0 comments on commit 876f575

Please sign in to comment.