WebGL2: Graphics context is sometimes lost in the built-in HTML viewer after backgrounding the app
I use your app to test WebGL2 graphics via the built-in HTML file viewer. Quite often, after minimizing the app and switching to other apps, the WebGL context gets lost and the canvas stops rendering anything (blank/black). Returning to the app does not restore rendering.
Expected behavior
After returning to the app, WebGL2 rendering should recover correctly (or the viewer should automatically restart the renderer) without requiring a full app restart.
Actual behavior
The context is lost and rendering never comes back. The only workaround is fully restarting the app.
Why this matters
A full restart resets the code editing history/undo-redo, so I lose recent edits. This is very disruptive.
Steps to reproduce
- Open the attached HTML file (WebGL2 canvas) in the built-in HTML viewer.
- Minimize the app.
- Open other apps until this app goes into the background and is effectively “suspended”.
- Return to the app.
- The canvas shows nothing and rendering does not recover.
Reproducibility
High. It happens frequently for me; with the attached HTML it’s almost 100% reproducible once the app is suspended in the background.
Environment
- Device: iPhone 13 mini
- OS: iOS 17.6
- Mode: built-in HTML viewer
- WebGL: WebGL2
Attachments
- (minimal reproduction)
Additional notes
This looks like a context loss on backgrounding. It may help to handle webglcontextlost / webglcontextrestored and/or recreate the context/resources when the app returns to the foreground, so the viewer can recover without requiring an app restart.
Customer support service by UserEcho
Thanks for the report and the repro file.
I’ve tried to reproduce this issue using your repo.html on multiple devices and iOS versions (iPhone 11 Pro running iOS 17.7 and iPhone 17 Pro running iOS 26.2), including backgrounding the app and running GPU-heavy workloads while Textastic is in the background. On return to Textastic, the WebGL2 content either continues rendering normally or the HTML viewer is reloaded by iOS, after which the animation runs again. I have not observed a case where the WebGL2 context is lost and never recovers.
I also verified that explicitly forcing a WebGL context loss and restore (using WEBGL_lose_context) works as expected.
So far I’m unable to reproduce the “context lost and never recovers” behavior you’re seeing. This may be specific to a particular device / iOS version combination (for example the iPhone 13 mini on iOS 17.6 mentioned in the report), or a WebKit issue that no longer occurs on newer iOS releases.
If you’re still able to reproduce this reliably on current hardware or iOS versions, additional details (device, iOS version, exact steps) would help investigate further.