Search code examples
javascriptgoogle-chrome

How to get the value of a Google Chrome flag using Javascript


My application is running into major WebGL performance issues with Google Chrome on Apple silicon devices, which is fixed by manually setting chrome://flags/#use-angle to OpenGL.

I would like to use pure Javascript code to read the value of this flag and then prompt users to make this setting change, if it is needed.

I already have Javascript code to test if the browser is Google Chrome, and I have the code I need to test if the device is using Apple silicon architecture. Specifically, I would like to read the value of this specific Chrome flag.

What options are available in 2024 to programmatically — specifically, with pure Javascript — read the value of this flag within the browser?

Note: A past question asks about setting the value of a flag programmatically, which I do not need or want. Another past question relates to using the command-line options to Chrome or Chromium, or parse a text file outside the browser, which is not what I am asking. I am asking about reading the value of the flag programmatically within the browser, using pure Javascript.


Solution

  • I don't think it's possible to directly read Chrome flags with js (probably for privacy reasons).

    To get more info on the renderer, you can use WEBGL_debug_renderer_info to check if ANGLE is being used for example

    const canvas = document.createElement('canvas');
    const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
    
    const debugInfo = gl?.getExtension('WEBGL_debug_renderer_info');
    if (debugInfo) {
      const renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
      console.log('WebGL Renderer:', renderer);
    }