WKWebView javascript call fails when app moves to foreground for Universal Link

Hello,

I have an intermittent problem that shows up when a user taps a Universal Link that opens my app.

I've got a WKWebView with a stored authentication cookie. Normally when the app runs the cookie is loaded from the locksmith storage and put into the webview's cookies. When the webview accesses the web app, the web app knows the user is authenticated.

When the app is brought to the foreground, a Javascript call is evaluated in the webview.

Scenario:

  • App has been used and the user is no longer in it. Time passes -- maybe a night?
  • User gets an email with a Universal Link and taps on it.
  • App opens, loads the link in the webview, and gets the unauthenticated version.
  • App sends the movedToForeground Javascript call and gets an error: "JavaScript execution returned a result of an unsupported type".
  • Error is captured and an app alert pops up asking if the user wants to reload.
  • User taps reload and gets the login form (again showing webview is not authenticated).

I can't easily reproduce this error. I can go back to the email, tap the link, and it loads the authenticated version without error. I can even kill the app, tap the link, and it correctly loads.

The process involves every part of the app that I'm not sure where to begin looking.

WKWebView javascript call fails when app moves to foreground for Universal Link
 
 
Q