title: Trying to display online pdf's in an android application (using kotlin) webview using google drive will occasionally produce errors
body: <p>I have been trying to fix this all day long. I am trying to display various pdf's saved online on a web view using google drive, so that it loads page by page, but doesn't download it locally.</p>
  
  <p>Whenever I go into the webview to load the pdf it will usually work, but once every couple of tries I will get the following error:</p>
  
  <pre><code>"Uncaught CustomError: Did not receive drive#about kind when fetching import map:undefined", source: https://www.gstatic.com/_/apps-viewer/_/js/k=apps-viewer.standalone.iw.nPmJUigVjYY.O/d=1/ct=zgms/rs=AC2dHMJ5W67xChDpdTOaSavkSV5aN0BM8g/m=main (92)
  [INFO:CONSOLE(92)] "Uncaught [object Object]", source: https://www.gstatic.com/_/apps-viewer/_/js/k=apps-viewer.standalone.iw.nPmJUigVjYY.O/d=1/ct=zgms/rs=AC2dHMJ5W67xChDpdTOaSavkSV5aN0BM8g/m=main (92)
  </code></pre>
  
  <p>I have been trying to find out what is causing this all day long but have not managed to fix it. Any Ideas what might be causing it/how I can fix it?</p>
  
  <p>I am coding this app using kotlin, here is the fragment I am using to display PDF's, it gets a pdf url from a database, the url itself is not problematic.</p>
  
  <pre><code>class WebViewPdf : Fragment() {
  
  lateinit var webView: WebView
  override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
      if (pdfLoadingPanel != null) {
          pdfLoadingPanel.visibility = View.GONE
      }
      var view = inflater.inflate(com.madortilofficialapps.tilquiz.R.layout.fragment_pdf_view, container, false)
      webView = view.findViewById(
              com.madortilofficialapps.tilquiz.R.id.webView) as WebView
      var googleDocs = "https://docs.google.com/viewer?embedded=true&amp;url="
      val url = arguments!!.getString("url")
      webView.invalidate()
      webView.settings.javaScriptEnabled = true
      webView.settings.setSupportZoom(true)
      webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null)
      webView.settings.domStorageEnabled = true
      var didLoadPDF = false
      Log.d("LKJLKHLKHLHLKHLHKLH","Starting")
      webView.webViewClient = object : WebViewClient() {
          override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
              super.onPageStarted(view, url, favicon)
              Log.d("lkhnjlkjlkj", "Loading")
              if (pdfLoadingPanel != null) {
                  pdfLoadingPanel.visibility = View.VISIBLE
              }
              didLoadPDF = true
          }
  
          override fun onPageFinished(view: WebView?, url: String?) {
              super.onPageFinished(view, url)
             if(!didLoadPDF){
                  webView.loadUrl(googleDocs + url)
              }else {
                  Log.d("dagfagaga", "Finished loading")
                  if (pdfLoadingPanel != null) {
                      pdfLoadingPanel.visibility = View.GONE
                  }
                 if(webView.title == ""){
                     webView.reload()
                 }
              }
          }
      }
      webView.loadUrl(googleDocs + url)
      return view
  }
  
  override fun onPause() {
      super.onPause()
      webView.clearCache(true)
      webView.getSettings().setAppCacheEnabled(false);
      activity?.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
  }
  
  override fun onDestroyView() {
      super.onDestroyView()
      webView.destroy()
  }
  
  override fun onResume() {
      super.onResume()
      activity?.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR)
  }
  </code></pre>
  
  <p>EDIT: I managed to fix it, here is how for people with this problem in the future. Basically I debugged the webView.Title and found that whenever it gave me the error the title was not what I wanted. continuing with that I found that for some reason, even though the url variable was a val, it changed after every time, adding the googleDocs variable to the start of it, becoming something like this: "<a href="https://docs.google.com/viewer?embedded=true&amp;url=https://docs.google.com/viewer?embedded=true&amp;url=https://docs.google.com/viewer?embedded=true&amp;url=example.pdf" rel="nofollow noreferrer">https://docs.google.com/viewer?embedded=true&amp;url=https://docs.google.com/viewer?embedded=true&amp;url=https://docs.google.com/viewer?embedded=true&amp;url=example.pdf</a>", so what I did was add the googleDocs to the URL in the start of the program, before I start the webView, then only load the URL by itself, that way even when the webView didn't load at first and tried to load again recursively the URL didn't grow.</p>