-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
70 lines (48 loc) · 1.68 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
title: "WEBGL_lose_context: restoreContext() method"
short-title: restoreContext()
slug: Web/API/WEBGL_lose_context/restoreContext
page-type: webgl-extension-method
browser-compat: api.WEBGL_lose_context.restoreContext
---
{{APIRef("WebGL")}}
The **WEBGL_lose_context.restoreContext()** method is part of the [WebGL API](/en-US/docs/Web/API/WebGL_API) and allows you to simulate
restoring the context of a {{domxref("WebGLRenderingContext")}} object.
## Syntax
```js-nolint
restoreContext()
```
### Parameters
None.
### Return value
None ({{jsxref("undefined")}}).
### Exceptions
Browsers may not report WebGL errors by default. WebGL's error reporting works by calling {{domxref("WEBGLRenderingContext.getError", "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`](/en-US/docs/Web/API/HTMLCanvasElement/webglcontextrestored_event)
event:
```js
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
canvas.addEventListener(
"webglcontextrestored",
(e) => {
console.log(e);
},
false,
);
gl.getExtension("WEBGL_lose_context").restoreContext();
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{domxref("WebGLRenderingContext.isContextLost()")}}
- Events:
[`webglcontextlost`](/en-US/docs/Web/API/HTMLCanvasElement/webglcontextlost_event),
[`webglcontextrestored`](/en-US/docs/Web/API/HTMLCanvasElement/webglcontextrestored_event),
[`webglcontextcreationerror`](/en-US/docs/Web/API/HTMLCanvasElement/webglcontextcreationerror_event)