"Unknown error" likely related to ByteDance WebView (TikTok)

The first question, of course, is whether this is an error you can reproduce for yourselves (with your own TikTok app). If so, the rest of this gets much easier; if not, you’re going to have to rely more on logging and writing custom error handlers to collect this information in the wild. (If you do this, I would advise testing your error handling code carefully - including with artificial JS errors, eg raised from native libraries or from the browser console.)

So, here are some strategies for getting more information:

If you’ve got hold of an ExternalError object in your custom error handler, check out its original_error property - that’s the (Python-wrapped) error object from Javascript! You can get its stack property, for example, to get a JS stack trace of what’s going wrong and where.

You can also consider selectively swallowing these errors, thereby preventing the disruptive red box from showing up. (Obviously, you’d still want to log all the error details you can get, stack traces included.)

Based on the traceback from the App Logs when users are using this code, does it happen while interacting with your app, or “out of nowhere”? If it’s out of nowhere, it’s much more likely to be a random error from the injected Javascript that Bytedance use for user tracking - which also means it’s probably safer to ignore. If it’s interfering with operation of your app, that’s more of a problem.