title: WebGL: get error/warning message text as a string
body: <p>When an error occurs within WebGL, a warning message is usually displayed in the browser's console.</p>
  
  <p>For example, trying to create a texture which is too big:</p>
  
  <pre><code>gl.texImage2D(
      gl.TEXTURE_2D,     // target
      0,                 // level
      gl.RGBA,           // internalformat
      1000000,           // width
      1000000,           // height
      0,                 // border
      gl.RGBA,           // format
      gl.UNSIGNED_BYTE,  // type
      null               // data
  );
  </code></pre>
  
  <p>Chrome and Safari display this warning message in the console:</p>
  
  <pre><code>WebGL: INVALID_VALUE: texImage2D: width or height out of range
  </code></pre>
  
  <p>Firefox displays this warning message:</p>
  
  <pre><code>Error: WebGL: texImage2D: the maximum width for level 0 is 4096
  </code></pre>
  
  <p>How can I programmatically obtain this message from WebGL?</p>
  
  <p>I'm looking for something like <code>gl.getErrorMessage()</code> which would return a string.</p>
  
  <h3>What I've tried</h3>
  
  <p>WebGL errors don't throw JavaScript errors, so it's not possible to <code>catch</code> them to get their <code>message</code> property.</p>
  
  <p><a href="https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetError.xml" rel="nofollow"><code>gl.getError()</code></a> only returns an <code>ErrorCode</code> enum value, such as <code>INVALID_VALUE</code>.</p>
  
  <p><a href="https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetShaderInfoLog.xml" rel="nofollow"><code>gl.getShaderInfoLog()</code></a> only provides error messages relating to a specific shader (eg. compilation errors).</p>
  
  <p><a href="https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetProgramInfoLog.xml" rel="nofollow"><code>gl.getProgramInfoLog()</code></a> only provides error messages relating to a specific program (eg. linking errors).</p>
  
  <p>Khronos have created a <a href="https://www.khronos.org/webgl/wiki/Debugging#Programmatically_Debugging_WebGL_applications" rel="nofollow">debugging wrapper</a> called <code>WebGLDebugUtils</code>, but it seems the only method relating to error messages is <code>glEnumToString()</code>, which converts an enum value (eg. <code>INVALID_VALUE</code>) to a string.</p>