2

So I have the following method to load a page on one part of my app. The page it's opening to is an Angular 2 app if that makes any difference. If I put a breakpoint and copy this URL into chrome in my emulator the page opens fine, but it doesn't in the app.

fun loadInbox() {
    inboxView = this.fragmentView!!.findViewById(R.id.webview_inbox)
    inboxView!!.webViewClient = object: WebViewClient() {
        override fun onPageFinished(view: WebView?, url: String?) {
            super.onPageFinished(view, url)

        }
    }
    inboxView!!.settings.javaScriptEnabled = true
    val url = "https://test.com/auth?r=m&t=$token"
    inboxView!!.loadUrl(url)
}

This is the error I see in Logcat.

06-22 18:31:55.760 13849-13849/com.test I/chromium: [INFO:CONSOLE(1)] "Error: Uncaught (in promise): TypeError: Cannot read property 'getItem' of null
    TypeError: Cannot read property 'getItem' of null
        at new e (https://www.test.com/main.541c7d5087cbecca24bd.bundle.js:1:23084)
        at t.get [as _AuthenticationService_75] (https://www.test.com/main.541c7d5087cbecca24bd.bundle.js:1:2255567)
        at t.getInternal (https://www.test.com/main.541c7d5087cbecca24bd.bundle.js:1:2261978)
        at t.e.get (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:342908)
        at t.injectorGet (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:282705)
        at e.get (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:280791)
        at t._getByKeyDefault (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:482195)
        at t._getByKey (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:481596)
        at t.get (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:479963)
        at t.injectorGet (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:282705)
        at t.createInternal (https://www.test.com/main.541c7d5087cbecca24bd.bundle.js:1:2041133)
        at t.createHostView (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:282240)
        at t.create (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:103524)
        at t.createComponent (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:195584)
        at t.activate (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:771819)
        at new J (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:833407)
        at N (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:830108)
        at N (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:829794)
        at https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:830622
        at t.invokeTask (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:826402)
        at Object.onInvokeTask (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:868037)
        at t.invokeTask (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:826323)
        at n.runTask (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:821843)
        at m (https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js:1:829002)", source: https://www.test.com/vendor.1de6bdcb0d523e2b996d.bundle.js (1)

Any ideas? I know I need javascript enabled, but as far as I can tell I did that correctly.

Jhorra
  • 6,233
  • 21
  • 69
  • 123
  • Chrome continues to display the web page when an Error was thrown from javascripts, however your app seems can't handle it. Maybe you can load a webpage which you are sure contains no error to see if it's the web page's fault. – Meow Cat 2012 Jun 23 '18 at 03:50
  • I'll give that a shot – Jhorra Jun 23 '18 at 04:06

1 Answers1

2

Based off your comment I was able to expand my search for a fix and found this: Android API 23. WebView how to ignore javascript errors

The Kotlin version of his answer for mine is this:

inboxView!!.settings.domStorageEnabled = true

Substitute inboxView for your Webview.

Jhorra
  • 6,233
  • 21
  • 69
  • 123