Solve flutter SecurityError: Failed to execute 'texImage2D' on 'WebGL2RenderingContext': The image element contains cross-origin data, and may not be loaded.

Created At: 2025-01-10 11:55:17 Updated At: 2025-01-11 15:49:53

Once you upgrade flutter, you may encounter the below issue

flutter SecurityError: Failed to execute 'texImage2D' on 'WebGL2RenderingContext': The image element contains cross-origin data, and may not be loaded.

There could be other errors that pop up too. But here the actual issue with image rendering. For me, the issue was CachedNetworkImage() plugin. 

For some reasons, CachedNetorkImage() could not render images correctly and throws a lot of error. You may also see error like "out of memory".

canvaskit/chromium/canvaskit.wasm 1:4658566                                     10032

canvaskit/chromium/canvaskit.wasm 1:4591464                                     9855

canvaskit/chromium/canvaskit.wasm 1:398764                                      1136

canvaskit/chromium/canvaskit.wasm 1:4600247                                     9881

canvaskit/chromium/canvaskit.wasm 1:282978                                      880

canvaskit/chromium/canvaskit.js 116:52                                          _drawPicture

canvaskit/chromium/canvaskit.js 49:299                                          drawPicture

lib/_engine/engine/canvaskit/canvas.dart 236:5                                  drawPicture

dart-sdk/lib/_internal/js_dev_runtime/private/js_array.dart 214:7               forEach]

lib/_engine/engine/canvaskit/surface.dart 126:13                               

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/canvaskit/surface.dart 122:16                                rasterizeToCanvas

lib/_engine/engine/canvaskit/offscreen_canvas_rasterizer.dart 52:39             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/canvaskit/offscreen_canvas_rasterizer.dart 50:16             rasterizeToCanvas

lib/_engine/engine/canvaskit/embedded_views.dart 378:24                         

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/canvaskit/embedded_views.dart 359:16                         submitFrame

lib/_engine/engine/canvaskit/rasterizer.dart 70:24                             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/canvaskit/rasterizer.dart 44:16                              draw

lib/_engine/engine/canvaskit/renderer.dart 451:21                               

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/canvaskit/renderer.dart 439:16                               [_renderScene]

lib/_engine/engine/canvaskit/renderer.dart 425:13                               

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/canvaskit/renderer.dart 421:16                               [_kickRenderLoop]

lib/_engine/engine/canvaskit/renderer.dart 417:15                               

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/canvaskit/renderer.dart 398:16                               renderScene

lib/_engine/engine/platform_dispatcher.dart 839:22                             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/platform_dispatcher.dart 821:16                              render

lib/_engine/engine/window.dart 106:5                                            render

packages/flutter/src/rendering/view.dart 354:7                                  compositeFrame

packages/flutter/src/rendering/binding.dart 614:19                              drawFrame

packages/flutter/src/widgets/binding.dart 1178:13                               drawFrame

packages/flutter/src/rendering/binding.dart 475:5                               [_handlePersistentFrameCallback]

packages/flutter/src/scheduler/binding.dart 1397:7                              [_invokeFrameCallback]

packages/flutter/src/scheduler/binding.dart 1318:9                              handleDrawFrame

packages/flutter/src/scheduler/binding.dart 1176:5                              [_handleDrawFrame]

lib/_engine/engine/platform_dispatcher.dart 1408:5                              invoke

lib/_engine/engine/platform_dispatcher.dart 310:5                               invokeOnDrawFrame

lib/_engine/engine/initialization.dart 187:36                                   

dart-sdk/lib/_internal/js_dev_runtime/patch/js_allow_interop_patch.dart 212:27  _callDartFunctionFast1

SecurityError: Failed to execute 'texImage2D' on 'WebGL2RenderingContext': The image element contains cross-origin data, and may not be loaded.

canvaskit/chromium/canvaskit.js 21:473                                          makeTexture

canvaskit/chromium/canvaskit.js 168:261                                         

canvaskit/chromium/canvaskit.js 167:348                                         N

canvaskit/chromium/canvaskit.wasm 1:4269394                                     8622

canvaskit/chromium/canvaskit.wasm 1:4836195                                     10662

canvaskit/chromium/canvaskit.wasm 1:1892315                                     3735

canvaskit/chromium/canvaskit.wasm 1:221077                                      757

canvaskit/chromium/canvaskit.wasm 1:1908742                                     3744

canvaskit/chromium/canvaskit.wasm 1:1169496                                     2607

canvaskit/chromium/canvaskit.wasm 1:3621520                                     6672

canvaskit/chromium/canvaskit.wasm 1:4596069                                     9861

canvaskit/chromium/canvaskit.wasm 1:436089                                      1259

canvaskit/chromium/canvaskit.wasm 1:873764                                      2052

canvaskit/chromium/canvaskit.wasm 1:1388586                                     2895

canvaskit/chromium/canvaskit.wasm 1:4658566                                     10032

canvaskit/chromium/canvaskit.wasm 1:4591464                                     9855

canvaskit/chromium/canvaskit.wasm 1:398764                                      1136

canvaskit/chromium/canvaskit.wasm 1:4600247                                     9881

canvaskit/chromium/canvaskit.wasm 1:282978                                      880

canvaskit/chromium/canvaskit.js 116:52                                          _drawPicture

canvaskit/chromium/canvaskit.js 49:299                                          drawPicture

lib/_engine/engine/canvaskit/canvas.dart 236:5                                  drawPicture

dart-sdk/lib/_internal/js_dev_runtime/private/js_array.dart 214:7               forEach]

lib/_engine/engine/canvaskit/surface.dart 126:13                               

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/canvaskit/surface.dart 122:16                                rasterizeToCanvas

lib/_engine/engine/canvaskit/offscreen_canvas_rasterizer.dart 52:39             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/canvaskit/offscreen_canvas_rasterizer.dart 50:16             rasterizeToCanvas

lib/_engine/engine/canvaskit/embedded_views.dart 378:24                         

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/canvaskit/embedded_views.dart 359:16                         submitFrame

lib/_engine/engine/canvaskit/rasterizer.dart 70:24                             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/canvaskit/rasterizer.dart 44:16                              draw

lib/_engine/engine/canvaskit/renderer.dart 451:21                               

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/canvaskit/renderer.dart 439:16                               [_renderScene]

lib/_engine/engine/canvaskit/renderer.dart 425:13                               

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/canvaskit/renderer.dart 421:16                               [_kickRenderLoop]

lib/_engine/engine/canvaskit/renderer.dart 417:15                               

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/canvaskit/renderer.dart 398:16                               renderScene

lib/_engine/engine/platform_dispatcher.dart 839:22                             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 610:19             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 634:23             

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 532:3              _asyncStartSync

lib/_engine/engine/platform_dispatcher.dart 821:16                              render

lib/_engine/engine/window.dart 106:5                                            render

packages/flutter/src/rendering/view.dart 354:7                                  compositeFrame

packages/flutter/src/rendering/binding.dart 614:19                              drawFrame

packages/flutter/src/widgets/binding.dart 1178:13                               drawFrame

packages/flutter/src/rendering/binding.dart 475:5                               [_handlePersistentFrameCallback]

packages/flutter/src/scheduler/binding.dart 1397:7                              [_invokeFrameCallback]

packages/flutter/src/scheduler/binding.dart 1318:9                              handleDrawFrame

packages/flutter/src/scheduler/binding.dart 1176:5                              [_handleDrawFrame]

lib/_engine/engine/platform_dispatcher.dart 1408:5                              invoke

lib/_engine/engine/platform_dispatcher.dart 310:5                               invokeOnDrawFrame

lib/_engine/engine/initialization.dart 187:36                                   

This error appears on Flutter web version. If you encounter this issue, then just replace, CachedNetworkImage() with Image.network().

Once you do that, you will see, your app does not have the error anymore. You can do the below conditional check

Comment

Add Reviews