Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-14179

Cordova is not initialized properly when using Android System Webview v67

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Cannot Reproduce
    • cordova-android-7.0.0
    • None
    • cordova-android
    • None

    Description

      Cordova not initialized properly:

      06-28 10:52:14.774 12625-12625/com.example.hello E/CordovaBridge: gap_init called from restricted origin:
       

      I have looked into this issue and it seems that sometimes the origin URL is empty and that is the reason why the message above is shown.

      @Override
          public boolean onJsPrompt(WebView view, String origin, String message, String defaultValue, final JsPromptResult result) {
              Log.d(LOG_TAG, (tries++) +" onJsPrompt: "+origin);
              // Unlike the @JavascriptInterface bridge, this method is always called on the UI thread.
              String handledRet = parentEngine.bridge.promptOnJsPrompt(origin, message, defaultValue);
              if (handledRet != null) {
                  result.confirm(handledRet);
              } else {
                  dialogsHelper.showPrompt(message, defaultValue, new CordovaDialogsHelper.Result() {
                      @Override
                      public void gotResult(boolean success, String value) {
                          if (success) {
                              result.confirm(value);
                          } else {
                              result.cancel();
                          }
                      }
                  });
              }
              return true;
          }
      

      The strange think is that if you call view.getUrl() the url is return correctly. I was wondering, can be that used instead of the origin url ?

      This is an issue not that easy to reproduce, I managed to reproduce with a simple hello world cordova app.
      I did some tweaks to increase the occurrence of the issue:
      1. Enable "Don't keep activities" from the developer options
      2. Using "Recents" button open and close the app very fast
      3. I have attached the MainActvity.java that I used. There is some commented code that can be uncommented to increase the occurrence rate of the issue.

      Attachments

        1. cordova.log
          72 kB
          Cristian Totolici
        2. MainActivity.java
          3 kB
          Cristian Totolici

        Activity

          People

            Unassigned Unassigned
            cristian.totolici Cristian Totolici
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: