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

[weinre] setTimeout() and setInterval() usage with string arguments is busted

    Details

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

      original test case environment described below (Android), but problem will occur anywhere

      Description

      When using Android Emulator with weinre, JS errors log only sometimes.

      After reading that weinre needs a little time to setup before it will deal with console entries I made a test app that does the following:

      console.log( 'Hello now' );
      setTimeout( "console.log( 'Hello 10' )", 10000 );
      setTimeout( "console.log( 'Hello 20' )", 20000 );
      setTimeout( "console.log( 'Hello 30' )", 30000 );
      setTimeout( "console.log( 'Hello 40' )", 40000 );
      setTimeout( "console.log( 'Hello 50' )", 50000 );
      setTimeout( "console.log( 'Hello 60' )", 60000 );

      I've ran this many times and get similar logcat entries that look like this:

      06-05 23:10:19.992: D/PhoneGapLog(969): Hello now
      06-05 23:10:19.992: D/PhoneGapLog(969): file:///android_asset/www/index.html: Line 39 : Hello now
      06-05 23:10:20.000: I/Web Console(969): Hello now at file:///android_asset/www/index.html:39
      06-05 23:10:20.110: D/PhoneGapLog(969): error occurred: [unknown filename]:[unknown lineno]: [unknown message]
      06-05 23:10:20.110: D/PhoneGapLog(969): http://192.168.1.9:8081/target/target-script-min.js: Line 3176 : error occurred: [unknown filename]:[unknown lineno]: [unknown message]
      06-05 23:10:20.110: E/Web Console(969): error occurred: [unknown filename]:[unknown lineno]: [unknown message] at http://192.168.1.9:8081/target/target-script-min.js:3176
      06-05 23:10:20.120: D/PhoneGapLog(969): Uncaught TypeError: Cannot read property 'code' of undefined
      06-05 23:10:20.120: D/PhoneGapLog(969): http://192.168.1.9:8081/target/target-script-min.js: Line 3478 : Uncaught TypeError: Cannot read property 'code' of undefined
      06-05 23:10:20.120: E/Web Console(969): Uncaught TypeError: Cannot read property 'code' of undefined at http://192.168.1.9:8081/target/target-script-min.js:3478

      I see the 'Hello now' entry in logcat, but I don't see it in weinre. The only entry I see in weinre is 'Hello 10'.

      Does anyone know what these logcat errors mean or why only one out of my 7 test console messages are being picked up by weinre?

        Activity

        Hide
        cdelguercio Chris Del Guercio added a comment -

        Thanks Patrick! Everything works great now! I'm running Eclipse for Java (not Classic) with Cordova 1.8.1 and this latest weinre commit (apache-cordova-weinre-2.0.0-pre-H3FWTQKQ-incubating-bin).

        Also, I thank you for writing this wonderful program and enabling web programmers/designers everywhere to seamlessly transition into the mobile app market

        Show
        cdelguercio Chris Del Guercio added a comment - Thanks Patrick! Everything works great now! I'm running Eclipse for Java (not Classic) with Cordova 1.8.1 and this latest weinre commit (apache-cordova-weinre-2.0.0-pre-H3FWTQKQ-incubating-bin). Also, I thank you for writing this wonderful program and enabling web programmers/designers everywhere to seamlessly transition into the mobile app market
        Hide
        pmuellr Patrick Mueller added a comment -

        A build with this fix is available at the usual place:

        http://people.apache.org/~pmuellr/weinre/

        and npm has been updated so you can

        sudo npm -g install weinre
        
        Show
        pmuellr Patrick Mueller added a comment - A build with this fix is available at the usual place: http://people.apache.org/~pmuellr/weinre/ and npm has been updated so you can sudo npm -g install weinre
        Hide
        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=f277c2e2503b1ccac9bed1a456775c14066932a1

        weinre.web/modules/weinre/target/Target.coffee

        • removed the "error" handler on window, since it
          doesn't seem to actually work, and generates
          bogus messages at least in the test case
          provided.

        weinre.web/modules/weinre/target/Timeline.coffee

        • change the after- bits of the setTimeout/Interval()
          hooks to check that the before- bits ran
        • also changed the way contentLength and contentType
          are retrieved in the XHR hook to catch DOM errors,
          which Chrome recently started throwing
        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=f277c2e2503b1ccac9bed1a456775c14066932a1 weinre.web/modules/weinre/target/Target.coffee removed the "error" handler on window, since it doesn't seem to actually work, and generates bogus messages at least in the test case provided. weinre.web/modules/weinre/target/Timeline.coffee change the after- bits of the setTimeout/Interval() hooks to check that the before- bits ran also changed the way contentLength and contentType are retrieved in the XHR hook to catch DOM errors, which Chrome recently started throwing
        Hide
        pmuellr Patrick Mueller added a comment -

        The problem appears to be using a string as the argument to setTimeout()/setInterval() instead of a function. The code to handle string arguments in weinre has a bug. I'll go ahead and re-title this bug.

        Here's some code that does work:

        <script>
        var counter = 1 
        
        function printCounter() {
            console.log("Hello, " + counter++)
        }
        
        console.log( 'Hello now' );
        setInterval(printCounter, 5000)
        </script>
        
        Show
        pmuellr Patrick Mueller added a comment - The problem appears to be using a string as the argument to setTimeout()/setInterval() instead of a function. The code to handle string arguments in weinre has a bug. I'll go ahead and re-title this bug. Here's some code that does work: <script> var counter = 1 function printCounter() { console.log("Hello, " + counter++) } console.log( 'Hello now' ); setInterval(printCounter, 5000) </script>
        Hide
        pmuellr Patrick Mueller added a comment -

        When I let weinre get connected, I see the following messages in logcat:

        16.607: D/CordovaLog(1492):  Hello now
        16.607: D/CordovaLog(1492):  file:///android_asset/www/index.html: Line 11 : Hello now
        16.607: I/Web Console(1492): Hello now at file:///android_asset/www/index.html:11
        16.657: D/CordovaLog(1492):  error occurred: [unknown filename]:[unknown lineno]: [unknown message]
        16.657: D/CordovaLog(1492):  http://[weinre-server]:8081/target/target-script-min.js: Line 3176 : error occurred: [unknown filename]:[unknown lineno]: [unknown message]
        16.657: E/Web Console(1492): error occurred: [unknown filename]:[unknown lineno]: [unknown message] at http://[weinre-server]:8081/target/target-script-min.js:3176
        16.657: D/CordovaLog(1492):  Uncaught TypeError: Cannot read property 'code' of undefined
        16.657: D/CordovaLog(1492):  http://[weinre-server]:8081/target/target-script-min.js: Line 3450 : Uncaught TypeError: Cannot read property 'code' of undefined
        16.657: E/Web Console(1492): Uncaught TypeError: Cannot read property 'code' of undefined at http://[weinre-server]:8081/target/target-script-min.js:3450
        

        And it appears that the weinre console is displaying all the messages from the setInterval().

        Show
        pmuellr Patrick Mueller added a comment - When I let weinre get connected, I see the following messages in logcat: 16.607: D/CordovaLog(1492): Hello now 16.607: D/CordovaLog(1492): file:///android_asset/www/index.html: Line 11 : Hello now 16.607: I/Web Console(1492): Hello now at file:///android_asset/www/index.html:11 16.657: D/CordovaLog(1492): error occurred: [unknown filename]:[unknown lineno]: [unknown message] 16.657: D/CordovaLog(1492): http://[weinre-server]:8081/target/target-script-min.js: Line 3176 : error occurred: [unknown filename]:[unknown lineno]: [unknown message] 16.657: E/Web Console(1492): error occurred: [unknown filename]:[unknown lineno]: [unknown message] at http://[weinre-server]:8081/target/target-script-min.js:3176 16.657: D/CordovaLog(1492): Uncaught TypeError: Cannot read property 'code' of undefined 16.657: D/CordovaLog(1492): http://[weinre-server]:8081/target/target-script-min.js: Line 3450 : Uncaught TypeError: Cannot read property 'code' of undefined 16.657: E/Web Console(1492): Uncaught TypeError: Cannot read property 'code' of undefined at http://[weinre-server]:8081/target/target-script-min.js:3450 And it appears that the weinre console is displaying all the messages from the setInterval().
        Hide
        pmuellr Patrick Mueller added a comment -

        woops, duh, weinre wasn't connecting.

        Show
        pmuellr Patrick Mueller added a comment - woops, duh, weinre wasn't connecting.
        Hide
        pmuellr Patrick Mueller added a comment -

        Unable to reproduce with the following .html file, on Android platform 4.0.3, API level 15, Cordova 1.8.0 on the simulator:

        <!doctype html>
        
        <html>
        
        <head>
        <title>Cordova 1.8.0 Sample</title>
        <script src="http://localhost:8081/target/target-script-min.js#anonymous"></script>
        <script src="cordova-1.8.0.js"></script>
        
        <script>
        timer = 1
        console.log( 'Hello now' );
        setInterval( "console.log('Hello interval')", 5000)
        </script>
        
        </head>
        
        <body>
        <h1>Cordova 1.8.0 Sample</h1>
        <p>Messages should have been written to the console.
        </body>
        
        </html>
        
        Show
        pmuellr Patrick Mueller added a comment - Unable to reproduce with the following .html file, on Android platform 4.0.3, API level 15, Cordova 1.8.0 on the simulator: <!doctype html> <html> <head> <title>Cordova 1.8.0 Sample</title> <script src="http://localhost:8081/target/target-script-min.js#anonymous"></script> <script src="cordova-1.8.0.js"></script> <script> timer = 1 console.log( 'Hello now' ); setInterval( "console.log('Hello interval')", 5000) </script> </head> <body> <h1>Cordova 1.8.0 Sample</h1> <p>Messages should have been written to the console. </body> </html>
        Hide
        cdelguercio Chris Del Guercio added a comment -

        I've tried switching the order of the JS includes. That didn't do much. I'm currently installing a different version of eclipse (Eclipse Java vs. before Eclipse Classic) so see if that makes a difference. When that gets done I will try console.info() instead of console.log(). I don't think that's the problem though since it does output the one log entry.

        Show
        cdelguercio Chris Del Guercio added a comment - I've tried switching the order of the JS includes. That didn't do much. I'm currently installing a different version of eclipse (Eclipse Java vs. before Eclipse Classic) so see if that makes a difference. When that gets done I will try console.info() instead of console.log(). I don't think that's the problem though since it does output the one log entry.
        Hide
        pmuellr Patrick Mueller added a comment -

        Looking at the android version of the cordova.js file, I'm wondering if you ended up using their version of console.log instead of weinre's.

        Could you try the following things:

        • use console.info() instead of console.log()
        • include weinre's js file AFTER cordova's js file
        Show
        pmuellr Patrick Mueller added a comment - Looking at the android version of the cordova.js file, I'm wondering if you ended up using their version of console.log instead of weinre's. Could you try the following things: use console.info() instead of console.log() include weinre's js file AFTER cordova's js file
        Hide
        cdelguercio Chris Del Guercio added a comment -

        "I haven't used Android in a while - what is the "PhoneGapLog" vs "Web Console" bit difference?"

        I'm not an expert at PhoneGap, but it seems like PhoneGapLog is PG's error reporting mechanism, while Web Console is Android's. I don't really have any only info on that. :/

        "Complete guess, but I think you're not seeing "Hello now" in weinre because weinre hasn't been set up at the time. This ran very early?"

        Yes, I have read other bug reports/forum posts documenting this and I agree. I wasn't surprised that "Hello now" didn't show up, but I am surprised that all the other "Hello xx"s past 10 didn't.

        "The "[unknown filename]:[unknown lineno]:[unknown message]" bit sounds like it's coming from the onerror catcher. Is this an old version of Android?"

        Nope. I'm using version 18 of the SDK. In fact, my whole environment was set up just last week and I re-set it up when I got this error, to no avail.

        "The "Cannot read property 'code' of undefined sounds" sounds familiar, what version of weinre are you using?"

        I'm using 2.0.0-pre-H1FFX7OT-incubating. I've used the 1.6 (or whatever the latest non 2.0.0 version was) before and got different errors. 2.0.0-pre-H1FFX7OT-incubating has gotten me farther than any other version of weinre that I've tried.

        Show
        cdelguercio Chris Del Guercio added a comment - "I haven't used Android in a while - what is the "PhoneGapLog" vs "Web Console" bit difference?" I'm not an expert at PhoneGap, but it seems like PhoneGapLog is PG's error reporting mechanism, while Web Console is Android's. I don't really have any only info on that. :/ "Complete guess, but I think you're not seeing "Hello now" in weinre because weinre hasn't been set up at the time. This ran very early?" Yes, I have read other bug reports/forum posts documenting this and I agree. I wasn't surprised that "Hello now" didn't show up, but I am surprised that all the other "Hello xx"s past 10 didn't. "The " [unknown filename] : [unknown lineno] : [unknown message] " bit sounds like it's coming from the onerror catcher. Is this an old version of Android?" Nope. I'm using version 18 of the SDK. In fact, my whole environment was set up just last week and I re-set it up when I got this error, to no avail. "The "Cannot read property 'code' of undefined sounds" sounds familiar, what version of weinre are you using?" I'm using 2.0.0-pre-H1FFX7OT-incubating. I've used the 1.6 (or whatever the latest non 2.0.0 version was) before and got different errors. 2.0.0-pre-H1FFX7OT-incubating has gotten me farther than any other version of weinre that I've tried.
        Hide
        pmuellr Patrick Mueller added a comment -

        A few questions.

        • I assume the D/ I/ E/ prefixes on the messages are DEBUG, INFO, ERROR, etc.
        • I haven't used Android in a while - what is the "PhoneGapLog" vs "Web Console" bit difference?
        • Complete guess, but I think you're not seeing "Hello now" in weinre because weinre hasn't been set up at the time. This ran very early?
        • The "[unknown filename]:[unknown lineno]:[unknown message]" bit sounds like it's coming from the onerror catcher. Is this an old version of Android?
        • The "Cannot read property 'code' of undefined sounds" sounds familiar, what version of weinre are you using?
        Show
        pmuellr Patrick Mueller added a comment - A few questions. I assume the D/ I/ E/ prefixes on the messages are DEBUG, INFO, ERROR, etc. I haven't used Android in a while - what is the "PhoneGapLog" vs "Web Console" bit difference? Complete guess, but I think you're not seeing "Hello now" in weinre because weinre hasn't been set up at the time. This ran very early? The " [unknown filename] : [unknown lineno] : [unknown message] " bit sounds like it's coming from the onerror catcher. Is this an old version of Android? The "Cannot read property 'code' of undefined sounds" sounds familiar, what version of weinre are you using?
        Hide
        filmaj Filip Maj added a comment -

        Assigning to Pat

        Show
        filmaj Filip Maj added a comment - Assigning to Pat

          People

          • Assignee:
            pmuellr Patrick Mueller
            Reporter:
            cdelguercio Chris Del Guercio
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development