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

[weinre] "INVALID_STATE_ERR: DOM Exception 11" with chbrody/Cordova-SQLitePlugin

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.0
    • Fix Version/s: None
    • Component/s: cordova-weinre
    • Labels:
      None
    • Environment:

      OS X Lion 10.7.4, Google Chrome 22.0.1229.94, iOS6 iPhone Simulator

      Description

      When using weinre with Cordova-SQLitePlugin we get a javascript error:

      "INVALID_STATE_ERR: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable. File: http://192.168.1.169:1337/target/target-script-min.js?_=1350463351336 Line Number: 2794"

      Above line number corresponds to the function NetworkRequest.prototype.handleDone in target-script-min.js.

      As a work around I have just wrapped a try catch and made it fail silently:

      NetworkRequest.prototype.handleDone = function() {
      try {
      var description, sourceString, status, statusText, success, time;
      sourceString = this.xhr.responseText;
      Weinre.wi.NetworkNotify.setInitialContent(this.id, sourceString, "XHR");
      time = Date.now() / 1000.0;
      status = this.xhr.status;
      if (status === 0)

      { status = 200; }

      statusText = this.xhr.statusText;
      success = status >= 200 && status < 300;
      if (success)

      { return Weinre.wi.NetworkNotify.didFinishLoading(this.id, time); }

      else

      { description = "" + status + " - " + statusText; return Weinre.wi.NetworkNotify.didFailLoading(this.id, time, description); }

      } catch (e)

      { return; }

      };

      1. weinre_test.html
        3 kB
        Christiaan van Zyl

        Activity

        Show
        pmuellr Patrick Mueller added a comment - fixed in commit: https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-weinre.git;a=commit;h=441566b4cbbcfd6c886aea3f62883a3ca449dbd0 available at npm as version 2.0.0-pre-H8EOSCLN-incubating : https://npmjs.org/package/weinre
        Hide
        pmuellr Patrick Mueller added a comment -

        Noticed you're using modal prompts in your UI. Not great. The amount of time weinre will (by default) wait to hear back from a target before deciding it's dead is 15 sec. Use "weinre --?" and look at --deathTimeout.

        You can up that timeout to a few minutes, or something. Downside is that dead targets won't get marked as dead till that long, and will litter your Targets list in the Remote panel of weinre.

        Working modally like that, was difficult to keep weinre connected, and the workflow for hitting the link then the alert made turn-around per test too long. I changed to update a <span> I added to the doc, and was able to run the test repeatedly without any issues.

        Think I'll chalk this fix up as a winner.

        Show
        pmuellr Patrick Mueller added a comment - Noticed you're using modal prompts in your UI. Not great. The amount of time weinre will (by default) wait to hear back from a target before deciding it's dead is 15 sec. Use "weinre --?" and look at --deathTimeout. You can up that timeout to a few minutes, or something. Downside is that dead targets won't get marked as dead till that long, and will litter your Targets list in the Remote panel of weinre. Working modally like that, was difficult to keep weinre connected, and the workflow for hitting the link then the alert made turn-around per test too long. I changed to update a <span> I added to the doc, and was able to run the test repeatedly without any issues. Think I'll chalk this fix up as a winner.
        Hide
        pmuellr Patrick Mueller added a comment -

        I'll see if I can try this out.

        In the meantime:

        • you can try the 2.2.0 release candidate - http://markmail.org/message/c6f6tbcxfgstrepb
        • use the --debug flag on weinre, perhaps something interesting will be dumped to the terminal window
        • you should be able to run weinre AND real remote web inspector at the same time; pretty sure I've done this. You may get a clue about what's going on.
        Show
        pmuellr Patrick Mueller added a comment - I'll see if I can try this out. In the meantime: you can try the 2.2.0 release candidate - http://markmail.org/message/c6f6tbcxfgstrepb use the --debug flag on weinre, perhaps something interesting will be dumped to the terminal window you should be able to run weinre AND real remote web inspector at the same time; pretty sure I've done this. You may get a clue about what's going on.
        Hide
        mozey Christiaan van Zyl added a comment - - edited

        I've managed to separate out the code and created a test page, see attached: "weinre_test.html"

        Running this page with weinre 2.0.0-pre-H41DGW8S-incubating I get the error as described above intermittently. When I comment out the weinre include script I do not get the error.

        Running this page with the patch 2.0.0-pre-H8EOSCLN-incubating I do not get the error, but the connection to weinre dies after running the test a couple of times.

        I guess it might also be some bug in my test page code or the plugin...

        Show
        mozey Christiaan van Zyl added a comment - - edited I've managed to separate out the code and created a test page, see attached: "weinre_test.html" Running this page with weinre 2.0.0-pre-H41DGW8S-incubating I get the error as described above intermittently. When I comment out the weinre include script I do not get the error. Running this page with the patch 2.0.0-pre-H8EOSCLN-incubating I do not get the error, but the connection to weinre dies after running the test a couple of times. I guess it might also be some bug in my test page code or the plugin...
        Hide
        pmuellr Patrick Mueller added a comment -

        I have a patch available in a build. You can install it via:

        sudo npm -g uninstall weinre # for good measure

        sudo npm -g install http://people.apache.org/~pmuellr/weinre/builds/2.0.0-pre-H8EOSCLN-incubating/apache-cordova-weinre-2.0.0-pre-H8EOSCLN-incubating-bin.tar.gz # sorry for the long url

        If you get a chance to try this, let me know how it goes.

        Show
        pmuellr Patrick Mueller added a comment - I have a patch available in a build. You can install it via: sudo npm -g uninstall weinre # for good measure sudo npm -g install http://people.apache.org/~pmuellr/weinre/builds/2.0.0-pre-H8EOSCLN-incubating/apache-cordova-weinre-2.0.0-pre-H8EOSCLN-incubating-bin.tar.gz # sorry for the long url If you get a chance to try this, let me know how it goes.
        Hide
        mozey Christiaan van Zyl added a comment -

        > what version of Cordova are you using?

        2.1.0

        > what version of iOS are you using? Does it do the same thing on other versions of iOS?

        iPhone Simulator
        Version: 6.0 (10A403)

        > wanted to double-check that this error message is just spurious, and shouldn't be displayed, but is not hindering your app in any way.

        I only get the message intermittently. Had the app crash a couple of times but not nearly as much as I got that message, not sure if the message is related to the crash.

        Only get this message when writing to SQLite database using a plugin, so not sure how to extract a simple example of what is actually causing it.

        Show
        mozey Christiaan van Zyl added a comment - > what version of Cordova are you using? 2.1.0 > what version of iOS are you using? Does it do the same thing on other versions of iOS? iPhone Simulator Version: 6.0 (10A403) > wanted to double-check that this error message is just spurious, and shouldn't be displayed, but is not hindering your app in any way. I only get the message intermittently. Had the app crash a couple of times but not nearly as much as I got that message, not sure if the message is related to the crash. Only get this message when writing to SQLite database using a plugin, so not sure how to extract a simple example of what is actually causing it.
        Hide
        pmuellr Patrick Mueller added a comment -

        Couple of q's:

        • what version of Cordova are you using?
        • what version of iOS are you using? Does it do the same thing on other versions of iOS?
        • wanted to double-check that this error message is just spurious, and shouldn't be displayed, but is not hindering your app in any way.

        Looking at the code, I honestly can't see how this is even happening, at least with the current level of Cordova code. It seems like the XHR in question must be a "/!gap" XHR request, as part of the exec() impl [1], but ... it doesn't add any handlers, and so I don't see how it could "close" (or something) the XHR.

        I suppose it may be related to accessing the XHR responseText attribute if it's "not text" or something [2]. It would be nice to know if that's ALL we had to wrap, but ... this all seems so sketchy, it seems like wider-ranging try/catch would be safer.

        Seems like the safest thing to do is to put a try/catch around the getXhrEventHandler() function in NetworkRequest [3]. This may result in some XHR requests in weinre as not being complete, but there were going to be SOME KIND of problem with such requests anyway, apparently

        I've seen some seemingly spurious but innocuous "INVALID_STATE_ERR: DOM Exception blah blah" messages before, but never nailed down where they were coming from. Hopefully this will get rid of some/most/all of them!

        Thoughts?

        [1] https://github.com/apache/incubator-cordova-js/blob/master/lib/ios/exec.js#L124
        [2] http://www.w3.org/TR/XMLHttpRequest/#the-responsetext-attribute
        [3] https://github.com/apache/incubator-cordova-weinre/blob/master/weinre.web/modules/weinre/target/NetworkRequest.coffee#L189

        Show
        pmuellr Patrick Mueller added a comment - Couple of q's: what version of Cordova are you using? what version of iOS are you using? Does it do the same thing on other versions of iOS? wanted to double-check that this error message is just spurious, and shouldn't be displayed, but is not hindering your app in any way. Looking at the code, I honestly can't see how this is even happening, at least with the current level of Cordova code. It seems like the XHR in question must be a "/!gap" XHR request, as part of the exec() impl [1] , but ... it doesn't add any handlers, and so I don't see how it could "close" (or something) the XHR. I suppose it may be related to accessing the XHR responseText attribute if it's "not text" or something [2] . It would be nice to know if that's ALL we had to wrap, but ... this all seems so sketchy, it seems like wider-ranging try/catch would be safer. Seems like the safest thing to do is to put a try/catch around the getXhrEventHandler() function in NetworkRequest [3] . This may result in some XHR requests in weinre as not being complete, but there were going to be SOME KIND of problem with such requests anyway, apparently I've seen some seemingly spurious but innocuous "INVALID_STATE_ERR: DOM Exception blah blah" messages before, but never nailed down where they were coming from. Hopefully this will get rid of some/most/all of them! Thoughts? [1] https://github.com/apache/incubator-cordova-js/blob/master/lib/ios/exec.js#L124 [2] http://www.w3.org/TR/XMLHttpRequest/#the-responsetext-attribute [3] https://github.com/apache/incubator-cordova-weinre/blob/master/weinre.web/modules/weinre/target/NetworkRequest.coffee#L189
        Hide
        mozey Christiaan van Zyl added a comment -

        Thanks for the link, just upgraded to iOS6 yesterday. I might have to make my app work in Android as well at a later stage so keep up the good work!

        Show
        mozey Christiaan van Zyl added a comment - Thanks for the link, just upgraded to iOS6 yesterday. I might have to make my app work in Android as well at a later stage so keep up the good work!
        Hide
        pmuellr Patrick Mueller added a comment -

        Thanks. BTW, you really went out of your way there. If you're on iOS6, you don't need to use weinre any more, you can use real remote web inspector: http://moduscreate.com/enable-remote-web-inspector-in-ios-6/

        Show
        pmuellr Patrick Mueller added a comment - Thanks. BTW, you really went out of your way there. If you're on iOS6, you don't need to use weinre any more, you can use real remote web inspector: http://moduscreate.com/enable-remote-web-inspector-in-ios-6/
        Hide
        mozey Christiaan van Zyl added a comment -

        I assume so, the javascript error above has only occured when I am using weinre. I got the error text above from using window.onerror on the page running in the iOS6 iPhone Simulator.

        Show
        mozey Christiaan van Zyl added a comment - I assume so, the javascript error above has only occured when I am using weinre. I got the error text above from using window.onerror on the page running in the iOS6 iPhone Simulator.
        Hide
        pmuellr Patrick Mueller added a comment -

        Thanks Christian! I assume this is only a weinre issue, and not an issue with Cordova iOS itself. I've changed the components to indicate that, but correct me if I'm wrong.

        Show
        pmuellr Patrick Mueller added a comment - Thanks Christian! I assume this is only a weinre issue, and not an issue with Cordova iOS itself. I've changed the components to indicate that, but correct me if I'm wrong.

          People

          • Assignee:
            pmuellr Patrick Mueller
            Reporter:
            mozey Christiaan van Zyl
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development