File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,7 +18,11 @@ export const init = (app: App<Element>) => {
1818 dsn : VITE_SENTRY_DSN ,
1919 } ) ;
2020
21- Sentry . setContext ( 'gpu' , getGPUInfo ( ) ) ;
21+ try {
22+ Sentry . setContext ( 'gpu' , getGPUInfo ( ) ) ;
23+ } catch ( err ) {
24+ Sentry . captureException ( err ) ;
25+ }
2226} ;
2327
2428const setEnabled = ( enabled : boolean ) => {
Original file line number Diff line number Diff line change 1- import { Maybe } from '@/src/types' ;
1+ function getContextFromOffscreenCanvas ( ) {
2+ if ( typeof OffscreenCanvas === 'undefined' ) return null ;
3+ const canvas = new OffscreenCanvas ( 1 , 1 ) ;
4+ return canvas . getContext ( 'webgl2' ) as WebGL2RenderingContext | null ;
5+ }
6+
7+ function getContextFromHTMLCanvas ( ) {
8+ if ( typeof document === 'undefined' ) return null ;
9+ const canvas = document . createElement ( 'canvas' ) ;
10+ return canvas . getContext ( 'webgl2' ) as WebGL2RenderingContext | null ;
11+ }
212
313/**
414 * Retrieves the GPU renderer and vendor info.
515 * @returns
616 */
717export function getGPUInfo ( ) {
8- let canvas : Maybe < OffscreenCanvas | HTMLCanvasElement > = null ;
9- if ( typeof OffscreenCanvas !== 'undefined' ) {
10- canvas = new OffscreenCanvas ( 1 , 1 ) ;
11- } else if ( typeof document !== 'undefined' ) {
12- canvas = document . createElement ( 'canvas' ) ;
13- } else {
14- throw new Error ( 'Cannot init a canvas' ) ;
15- }
16-
17- const gl = canvas . getContext ( 'webgl2' ) as WebGL2RenderingContext ;
18+ // try offscreencanvas to support usage in webworkers
19+ const gl = getContextFromOffscreenCanvas ( ) ?? getContextFromHTMLCanvas ( ) ;
1820 if ( ! gl ) {
19- throw new Error ( 'Cannot get a WebGL2 context' ) ;
21+ throw new Error ( 'Cannot get a webgl2 context' ) ;
2022 }
2123
2224 const info = {
You can’t perform that action at this time.
0 commit comments