/
index.md
69 lines (48 loc) · 1.6 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
---
title: "WEBGL_lose_context: loseContext() method"
short-title: loseContext()
slug: Web/API/WEBGL_lose_context/loseContext
page-type: webgl-extension-method
browser-compat: api.WEBGL_lose_context.loseContext
---
{{APIRef("WebGL")}}
The **WEBGL_lose_context.loseContext()** method is part of the [WebGL API](/en-US/docs/Web/API/WebGL_API) and allows you to simulate losing
the context of a {{domxref("WebGLRenderingContext")}} context.
It triggers the steps described in the WebGL specification for handling context lost.
The context will remain lost until {{domxref("WEBGL_lose_context.restoreContext()")}} is
called.
## Syntax
```js-nolint
loseContext()
```
### Parameters
None.
### Return value
None ({{jsxref("undefined")}}).
## Examples
With this method, you can simulate the
[`webglcontextlost`](/en-US/docs/Web/API/HTMLCanvasElement/webglcontextlost_event)
event:
```js
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
canvas.addEventListener(
"webglcontextlost",
(e) => {
console.log(e);
},
false,
);
gl.getExtension("WEBGL_lose_context").loseContext();
// WebGLContextEvent event with type "webglcontextlost" is logged.
```
## 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)