getShaderInfoLog method

Returns errors which occur when compiling a shader.




var retVal = WebGLRenderingContext.getShaderInfoLog(shader);


shader [in]

Type: WebGLShader

The shader object.

Return value

Type: String

The information log.


Shader compilation errors are written to the shader's info log. To get compile status, call gl.getShaderParameter(myShader,gl.COMPILE_STATUS) to check for a failed compile. On a failed compile, call gl.getShaderInfoLog(myShader) to get the error information. This method only returns the info log, but doesn't clear the log like getError does.


This example creates and compiles a vertex or a fragment shader. It then calls getShaderParameter to check if the shader compiled correctly. If the shader fails to compile, getShaderInfoLog is called to retrieve the last error. For more info on this example, see Get started with WebGL.

// Loads a shader from a script tag
// Parameters:
//   WebGL context
//   id of script element containing the shader to load
function getShader(gl, id) {
  var shaderScript = document.getElementById(id);

  // error - element with supplied id couldn't be retrieved
  if (!shaderScript) {
    return null;

  // If successful, build a string representing the shader source
  var str = "";
  var k = shaderScript.firstChild;
  while (k) {
    if (k.nodeType == 3) {
      str += k.textContent;
    k = k.nextSibling;

  var shader;

  // Create shaders based on the type we set
  //   note: these types are commonly used, but not required
  if (shaderScript.type == "x-shader/x-fragment") {
    shader = gl.createShader(gl.FRAGMENT_SHADER);
  } else if (shaderScript.type == "x-shader/x-vertex") {
    shader = gl.createShader(gl.VERTEX_SHADER);
  } else {
    return null;

  gl.shaderSource(shader, str);

  // Check the compile status, return an error if failed
  if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
    return null;

  return shader;

See also