hotwired / turbo-android

Android framework for making Turbo native apps
MIT License
425 stars 51 forks source link

Uncaught ReferenceError: turboNative is not defined when recover from background #147

Closed fffx closed 6 months ago

fffx commented 3 years ago

Open Turbo demo, click on Open a slow-loading webpage, put it in background by switch to another app, play around for a few minutes, when you see a message

dev.hotwire.turbo.demo W/cr_ChildProcessConn: onServiceDisconnected (crash or killed by oom)

then go back to Turbo demo, got the error

2021-02-09 10:44:37.815 20103-20103/dev.hotwire.turbo.demo D/TurboLog: fragment.onStart .................. [session: main, location: https://turbo-native-demo.glitch.me/slow, fragment: WebFragment]
2021-02-09 10:44:39.898 20103-20103/dev.hotwire.turbo.demo D/TurboLog: fragment.onStop ................... [session: main, location: https://turbo-native-demo.glitch.me/slow, fragment: WebFragment]
2021-02-09 10:44:53.297 20103-20142/dev.hotwire.turbo.demo W/cr_ChildProcessConn: onServiceDisconnected (crash or killed by oom): pid=20145 bindings:W S state:3 counts:0,0,0,1,
2021-02-09 10:44:53.439 20103-20103/dev.hotwire.turbo.demo E/chromium: [ERROR:aw_browser_terminator.cc(123)] Renderer process (20145) crash detected (code -1).
2021-02-09 10:44:53.447 20103-20103/dev.hotwire.turbo.demo D/TurboLog: onRenderProcessGone ............... [session: main, didCrash: false]
2021-02-09 10:44:53.448 20103-20103/dev.hotwire.turbo.demo D/TurboLog: shouldNavigateToLocation .......... [session: main, location: https://turbo-native-demo.glitch.me/slow, shouldNavigate: true, fragment: WebFragment]
2021-02-09 10:44:53.462 20103-20103/dev.hotwire.turbo.demo D/TurboLog: navigate .......................... [session: main, location: https://turbo-native-demo.glitch.me/slow, options: TurboVisitOptions(action=REPLACE, snapshotHTML=null, response=null), currentContext: DEFAULT, newContext: DEFAULT, presentation: REPLACE, fragment: WebFragment]
2021-02-09 10:44:53.463 20103-20103/dev.hotwire.turbo.demo D/TurboLog: navigateWithinContext ............. [session: main, location: https://turbo-native-demo.glitch.me/slow, presentation: REPLACE, fragment: WebFragment]
2021-02-09 10:44:53.513 20103-20103/dev.hotwire.turbo.demo I/FragmentNavigator: Ignoring popBackStack() call: FragmentManager has already saved its state
2021-02-09 10:44:53.516 20103-20103/dev.hotwire.turbo.demo D/TurboLog: navigateToLocation ................ [session: main, location: https://turbo-native-demo.glitch.me/slow, uri: turbo://fragment/web, fragment: WebFragment]
2021-02-09 10:44:53.519 20103-20103/dev.hotwire.turbo.demo I/FragmentNavigator: Ignoring navigate() call: FragmentManager has already saved its state
2021-02-09 10:45:06.106 20103-20103/dev.hotwire.turbo.demo D/TurboLog: fragment.onStart .................. [session: main, location: https://turbo-native-demo.glitch.me/slow, fragment: WebFragment]
2021-02-09 10:45:06.194 20103-20103/dev.hotwire.turbo.demo D/TurboLog: visitLocation ..................... [session: main, location: https://turbo-native-demo.glitch.me/slow, options: TurboVisitOptions(action=RESTORE, snapshotHTML=null, response=null), restorationIdentifier: 7e91e5dc-2927-4a13-9a3a-eab944c2b94b]
2021-02-09 10:45:06.473 20103-20103/dev.hotwire.turbo.demo I/chromium: [INFO:CONSOLE(1)] "Uncaught ReferenceError: turboNative is not defined", source:  (1)

My device info: Redmi k30 Pro Android 11 MIUI 12.2.2 stable version

jayohms commented 3 years ago

Thanks for this report. It looks like the WebView render process was killed by the OS while the app was in the background.

I'll try to replicate this and see how the app state can be restored properly when the render process is gone. Note, I probably won't be able to get to this for a little awhile, and this behavior should be a rare occurrence.

Bramjetten commented 3 years ago

I sometimes get this same error when navigating to a login modal after a 401. Dismissing the modal (and triggering another login modal caused by a 401) often fixes it.

VadimGuryanov commented 3 years ago

Hi! Faced the same problem. When I navigate between tabs in webview, which are loaded using js, and after navigate to another fragment using the navigate method, then I receive the same error appears in the console. After that, the page is not loaded. Also, if you go back, the web view is blocked and cannot be scrolled.

delegate.navigate(
    location = BuildConfig.BASE_URL + path,
    options = TurboVisitOptions(action = TurboVisitAction.REPLACE)
)         
......
D/TurboLog: navigate .......................... [session: main, location: /events, options: TurboVisitOptions(action=REPLACE, snapshotHTML=null, response=null), currentContext: DEFAULT, newContext: DEFAULT, presentation: REPLACE, fragment: CoursesFragment]
    navigateWithinContext ............. [session: main, location: /events, presentation: REPLACE, fragment: CoursesFragment]
W/ContentCatcher: Failed to notify a WebView
D/TurboLog: navigateToLocation ................ [session: main, location: /events, uri: turbo://fragment/web/events, fragment: CoursesFragment]
D/TurboLog: fragment.onStop ................... [session: main, location: /courses, fragment: CoursesFragment]
D/TurboLog: fragment.onViewCreated ............ [session: main, location: /events, fragment: EventsFragment]
D/TurboLog: fragment.onStart .................. [session: main, location: /events, fragment: EventsFragment]
W/ContentCatcher: Failed to notify a WebView
D/TurboLog: visitLocation ..................... [session: main, location: /events, options: TurboVisitOptions(action=ADVANCE, snapshotHTML=null, response=null), restorationIdentifier: ]
I/chromium: [INFO:CONSOLE(1)] “Uncaught ReferenceError: turboNative is not defined”, source: /lessons (1)
D/ViewRootImpl[MainActivity]: changeCanvasOpacity: opaque=false
D/ViewRootImpl[MainActivity]: changeCanvasOpacity: opaque=true
D/TurboLog: fragment.onStop ................... [session: main, location: /events, fragment: EventsFragment]
I/chromium: [INFO:CONSOLE(2)] “WebSocket connection to ‘wss://app.impactplus.com/cable’ failed: WebSocket is closed before the connection is established.“, source: .../js/application-0ccec25edd3a996ab.js (2)
........
aschneiderGit commented 2 years ago

Got same error with Devise logging : if i send a wrong login, i got the error with my second attemp. I fix it by force the Devise::FailureApp to call redirect instead of recall in my devise.rb : class TurboFailureApp < Devise::FailureApp


class TurboFailureApp < Devise::FailureApp
  def respond
    if http_auth?
      http_auth
    elsif warden_options[:recall]
      redirect
    else
      redirect
    end
  end
end```

I let the `elsif warden_options[:recall]` to easly compare my new function with the super function, but of course we can juste do a ` else redirect`