WEBGL_lose_context: restoreContext() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.

The restoreContext() method of the WEBGL_lose_context extension is part of the WebGL API and allows you to simulate restoring the context of a WebGLRenderingContext.

It triggers the steps described in the WebGL specification for handling context restored. The context is not usable until the webglcontextrestored event is fired.

Syntax

js
restoreContext()

Parameters

None.

Return value

None (undefined).

Exceptions

Browsers may not report WebGL errors by default. WebGL's error reporting works by calling getError() and checking for errors. The following exceptions may be thrown:

INVALID_OPERATION

Thrown if the context was not lost.

Examples

With this method, you can simulate the webglcontextrestored event:

js
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");

canvas.addEventListener("webglcontextrestored", (e) => {
  console.log(e);
});

gl.getExtension("WEBGL_lose_context").restoreContext();

Specifications

Specification
WebGL WEBGL_lose_context Khronos Ratified Extension Specification

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
restoreContext
Chrome – Full support
Chrome 26 (Release date: 2013-03-26)
footnote Full support
Edge – Full support
Edge 17 (Release date: 2018-04-30)
footnote Full support
Firefox – No support
Firefox 19 – 57 (Release date: 2013-02-19)
prefix
footnote Removed in 58 and later
prefix Implemented with the vendor prefix: MOZ_
Firefox – Full support
Firefox 22 (Release date: 2013-06-25)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 8 (Release date: 2014-10-16)
footnote Full support
Chrome Android – Full support
Chrome Android 26 (Release date: 2013-04-03)
footnote Full support
Firefox for Android – No support
Firefox for Android 19 – 57 (Release date: 2013-02-19)
prefix
footnote Removed in 58 and later
prefix Implemented with the vendor prefix: MOZ_
Firefox for Android – Full support
Firefox for Android 22 (Release date: 2013-06-25)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 8 (Release date: 2014-09-17)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1.5 (Release date: 2013-09-25)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 8 (Release date: 2014-09-17)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also