Android WebView OffscreenCanvas renders correctly in Web Worker but is not composited / shows blank after Activity resume


Environment

  • **Platform:**​ Android native app (Java / Kotlin)

  • **WebView:**​ Android WebView with hardware acceleration enabled

  • **Android version:**​ Android 10

  • **WebView version / Chrome version:**​ 100.0.4896.127

  • **Device:**​ [Oppo, Huawei]

  • Architecture:

    • Two Activities: MainActivity and SecondActivity

    • MainActivity contains a WebView

    • The WebView loads an HTML page

    • The page uses canvas.transferControlToOffscreen()

    • Rendering is performed in a Web Worker​ using OffscreenCanvas

What I’m trying to do

I want content rendered with OffscreenCanvas to continue displaying correctly after the user navigates away from MainActivity and then returns.

Steps to reproduce

  1. Launch MainActivity

  2. WebView loads the HTML page

  3. The page transfers control of a <canvas> to a Web Worker via transferControlToOffscreen()

  4. The Web Worker renders content into the OffscreenCanvas ✅

  5. The content is displayed correctly on screen ✅

  6. Navigate from MainActivity to ArticleActivity

  7. Return to MainActivity

  8. WebView.onResume() is called in MainActivity.onResume()

  9. Trigger a re-render or UI update that causes the canvas content to change

Expected behavior

The OffscreenCanvas content should be displayed correctly after returning to MainActivity.

Actual behavior

After returning to MainActivity, the OffscreenCanvas area becomes completely blank​ when the content is re-rendered or updated.

Key debugging observation

When the canvas appears blank, calling:

canvas.toDataURL()

from JavaScript successfully returns the complete and correct image data.

This proves that:

✅ The Web Worker is rendering correctly

✅ Pixel data is written to the OffscreenCanvas backing buffer

✅ The issue is not​ in the JavaScript or rendering logic

What I have ruled out

After the blank screen appears, calling:

location.reload()

does not​ fix the issue. The entire page, JavaScript context, Web Worker, and transferControlToOffscreen() are re-initialized, but the canvas still does not display.

This suggests the underlying Android WebView rendering pipeline / GPU context is corrupted or not restored, rather than the JS state.

What I have already tried (without success)

JavaScript / rendering side

  • Resizing the canvas

  • Forcing reflow / repaint

  • Using requestAnimationFrame

  • Re-submitting frames from the Worker

Android / WebView side

  • Calling webView.onResume() in onResume()

  • Calling webView.postInvalidate()

  • Forcing rendering via webView.evaluateJavascript(...)

  • Toggling setLayerType() between:

    • LAYER_TYPE_HARDWARE

    • LAYER_TYPE_SOFTWARE

  • Recreating the OffscreenCanvas on visibilitychange

None of these approaches resolved the issue.

Question

How can I restore OffscreenCanvas display after Activity resume, without recreating the WebView or reloading the page?

Any guidance, official API, Chromium-internal insight, or a confirmed workaround would be appreciated.

Repo link

https://github.com/y1j2x34/android-webview-offscreencanvas-issue

0
Sep 20 at 4:06 AM
User Avatarchienhsin Yang
#android#canvas#webview#offscreen-canvas

No answer found for this question yet.