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

Recently, we’re logging a lot of “ExternalError: Unknown error” JS errors. Looking at the User Agent strings we save in our app logs, we believe these errors happen when our app is opened in TikTok’s WebView instead of a standard browser. The errors happen pretty much anywhere throughout the app and whenever they happen, multiple of these errors seem to fire off in a single burst.

We tried extending the Anvil Runtime JS error handler to log more information, but there doesn’t seem to be more info available.

Has anyone encountered the same issue and been able to solve it, or does anyone have any ideas on how to go about addressing this? The errors look like they are very disruptive to our users and TikTok is a significant marketing avenue for us.

1 Like

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.

We’ve only been able to reproduce one very specific circumstance in which these errors arise, and not consistently.

The main issue is that so far we have been unable to log more information for these particular errors (ExternalError: Unknown error). The original_error property is literally just the string “Unknown error”: anvil-runtime/runner.js at 8b066fcb9118392e2238827e0a91f75c9cfa5b03 · anvil-works/anvil-runtime · GitHub Do you know of any other ways to get more information? Our attempts to extend the Anvil Runtime JS Error handler by logging the event’s currentTarget information just returned nulls as well.

So I am somewhat hesitant to just ignore the errors solely on the basis of them arising in the TikTok context and the error type + string, as this might lead us to ignore genuine disruptive errors.