when I CreateScreenshotUsingRenderTarget, it can always produce screenshots normally
But when I use CreateScreenshotAsync, sometimes it can be generated normally, but there is also a probability of exceptions as follows
I don’t understand why there are these differences, but in order to achieve functionality, I chose to use CreateScreenshotUsingRenderTarget for generation. However, I encountered a problem, which is that it cannot run properly on iOS because it uses offscreencanvas for generation. Older versions of iOS do not support offscreencanvas. Looking at the code where the error occurred, would it be better to include error capture in offscreencanvas initialization?
After I copy these changes in your PR to my local Babylon, this error was solved. But the image captured was all black. And it’s also only on the phone that not support OffscreenCanvas.
And I have tried both CreateScreenshotUsingRenderTargetAsync and CreateScreenshotAsync
Thanks for your answer. But I think it’s not a timing problem. I take a screenshot when I manually click the button. Even after waiting several minutes, it’s still not working. I also tried your code, adding setTimeout, not work…
I wonder if there are some changes about the screenshot function about the compatibility problem. And I missed them in my path for my local Babylon package.
This issue occurs because older versions of iOS Safari do not support OffscreenCanvas, while Babylon.js may still try to use it internally when generating screenshots using render targets. When that happens, it leads to the error “Can’t find variable: OffscreenCanvas.”
On some devices everything works fine, but on older iOS versions it can fail depending on which rendering path is chosen at runtime.
To avoid this problem, it is better to use the regular screenshot method instead of the render-target approach on iOS, as it is more stable and widely compatible. If an external solution is acceptable, services such as this Screenshot API. It can also be considered for capturing screenshots outside the device environment.