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

Weinre fails to load in browsers without a built-in development console

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: weinre
    • Environment:

      Windows Phone 8.0, iOS, Android

      Description

      I couldn't work out where to submit a pull request, so I'm doing an issue report instead. Additionally, this issue applies to version 2.0.0-pre-HH0SN197 of Weinre, but I don't know which version of Cordova that maps to.

      This issue has been a massive pain to debug, as the issue is not present on desktop computers and there are no debugging tools on mobile devices, hence why I need Weinre in the first place! In fact, the issue is even more specific than that: The issue affects all browsers WITHOUT debugging tools.

      The error is: "Unable to set property __original of undefined or null reference." The issue occurs on line 172 of Console.amd.js. In order to fix it, I added the following lines of code above line 168:

      if(!window.console)
      {
      window.console = {};
      }

      I'm sure there's a more elegant way of solving this, but it does the trick.

      Good luck!

        Activity

        Hide
        pmuellr Patrick Mueller added a comment -

        Thanks Joshua!

        What mobile platform are you running on that doesn't support console? Of the environments listed - wp8, iOS, Android - I thought we already had weinre working - and recent-ish releases of iOS and Android have native debugging stories as well.

        Show
        pmuellr Patrick Mueller added a comment - Thanks Joshua! What mobile platform are you running on that doesn't support console? Of the environments listed - wp8, iOS, Android - I thought we already had weinre working - and recent-ish releases of iOS and Android have native debugging stories as well.
        Hide
        YM_Industries Joshua Walsh added a comment - - edited

        Hi, sorry for not making this clear. I was referring to platforms that don't have an inbuilt JS console. All the platforms I tested have a working Weinre console once I had applied my fix.

        I don't think I explained the issue well at all, so I'll try again:

        Weinre overrides window.console.log(). It does not first check that window.console exists. This results in an "Unable to set property of undefined" error. Setting window.console to an empty array if it doesn't already exist fixes the issue, and allows Weinre's console to function perfectly.

        Show
        YM_Industries Joshua Walsh added a comment - - edited Hi, sorry for not making this clear. I was referring to platforms that don't have an inbuilt JS console. All the platforms I tested have a working Weinre console once I had applied my fix. I don't think I explained the issue well at all, so I'll try again: Weinre overrides window.console.log(). It does not first check that window.console exists. This results in an "Unable to set property of undefined" error. Setting window.console to an empty array if it doesn't already exist fixes the issue, and allows Weinre's console to function perfectly.
        Hide
        YM_Industries Joshua Walsh added a comment -

        I have a suggestion to go with this issue. When the code sets window.console to an empty object, it should warn the user that it has done so. Cross-browser handling of window.console is definitely something the website should do, as otherwise the website code may fall over in production (when Weinre is removed) on unsupported devices.

        Show
        YM_Industries Joshua Walsh added a comment - I have a suggestion to go with this issue. When the code sets window.console to an empty object, it should warn the user that it has done so. Cross-browser handling of window.console is definitely something the website should do, as otherwise the website code may fall over in production (when Weinre is removed) on unsupported devices.
        Hide
        pmuellr Patrick Mueller added a comment -

        Joshua, I understood the problem, was curious about what platforms don't have a "console" object. I'm not aware of any that don't. I'd obviously like to test this, and if there's some device I already have or can get cheap or borrow that exhibits this behaviour, I'd like to try.

        w/r/t warning the user, I guess we'd do this in the console itself? Kinda weird, eh? "warning: you are running on a platform without a console" displayed in their console I think we have a way of sending weinre console messages from the debug target, but will have to check.

        Show
        pmuellr Patrick Mueller added a comment - Joshua, I understood the problem, was curious about what platforms don't have a "console" object. I'm not aware of any that don't. I'd obviously like to test this, and if there's some device I already have or can get cheap or borrow that exhibits this behaviour, I'd like to try. w/r/t warning the user, I guess we'd do this in the console itself? Kinda weird, eh? "warning: you are running on a platform without a console" displayed in their console I think we have a way of sending weinre console messages from the debug target, but will have to check.
        Hide
        YM_Industries Joshua Walsh added a comment -

        In my testing this issue occurred on all mobile platforms.

        Make a simple webpage. No external scripts, no dependencies or includes. In the body, make a div with an id of 'test' and immediately below that make a script block:

        document.getElementById('test').innerText = typeof(window.console);

        Execute this on a desktop browser. You should see 'object' on the page. Execute on a mobile device and you should see 'undefined' instead.

        I was able to reproduce this issue on all of operating systems above. I used the Firefox app on Android, and it's irrelevant which browser I used on iOS and WP as they are all forced to use the same engine anyway.

        As for buying a cheap device, you can use Windows Phone 8.0 SDK to make a WP8 emulator for free. Install the SDK, launch Visual Studio, make a new Windows Phone 8.0 App project and click on the launch emulator option. The browser is properly emulated to use the exact same engine as present on a real Windows Phone.

        Show
        YM_Industries Joshua Walsh added a comment - In my testing this issue occurred on all mobile platforms. Make a simple webpage. No external scripts, no dependencies or includes. In the body, make a div with an id of 'test' and immediately below that make a script block: document.getElementById('test').innerText = typeof(window.console); Execute this on a desktop browser. You should see 'object' on the page. Execute on a mobile device and you should see 'undefined' instead. I was able to reproduce this issue on all of operating systems above. I used the Firefox app on Android, and it's irrelevant which browser I used on iOS and WP as they are all forced to use the same engine anyway. As for buying a cheap device, you can use Windows Phone 8.0 SDK to make a WP8 emulator for free. Install the SDK, launch Visual Studio, make a new Windows Phone 8.0 App project and click on the launch emulator option. The browser is properly emulated to use the exact same engine as present on a real Windows Phone.
        Hide
        YM_Industries Joshua Walsh added a comment -

        Oops, just noticed my typo in the title, that's embarrassing. In my defence, I wrote this report just before heading home on Friday, so I was tired.

        Fixed now.

        Show
        YM_Industries Joshua Walsh added a comment - Oops, just noticed my typo in the title, that's embarrassing. In my defence, I wrote this report just before heading home on Friday, so I was tired. Fixed now.
        Hide
        pmuellr Patrick Mueller added a comment -

        hmmm, last I remember, you could certainly use `console.log()` in iOS and Android - can't remember about wp8. I do know weinre works on all those platforms. The test you made isn't necessarily complete; the console object may well be injected into the global scope, and not available as a property of the "window" object.

        So, still trying to figure out your root problem; why did you need to add the code that you added. Could you only get weinre to work on iOS and Android and wp8 by modifying that code? If so, that's a weird regression since weinre has worked in the past on those platforms.

        Also, as I noted earlier, you don't really need to use weinre for recent Android or iOS devices anyway, since both platforms have web debugging support available now.

        Show
        pmuellr Patrick Mueller added a comment - hmmm, last I remember, you could certainly use `console.log()` in iOS and Android - can't remember about wp8. I do know weinre works on all those platforms. The test you made isn't necessarily complete; the console object may well be injected into the global scope, and not available as a property of the "window" object. So, still trying to figure out your root problem; why did you need to add the code that you added. Could you only get weinre to work on iOS and Android and wp8 by modifying that code? If so, that's a weird regression since weinre has worked in the past on those platforms. Also, as I noted earlier, you don't really need to use weinre for recent Android or iOS devices anyway, since both platforms have web debugging support available now.
        Hide
        YM_Industries Joshua Walsh added a comment -

        "hmmm, last I remember, you could certainly use `console.log()` in iOS and Android"
        Perhaps I'm using an older version of those then, because I hooked window.onerror and that was the error I was getting.

        "the console object may well be injected into the global scope, and not available as a property of the "window" object"
        In JavaScript, the window object IS the global scope.
        testVariable = "test";
        console.log(window.testVariable); //Logs "test" in the console

        "Could you only get weinre to work on iOS and Android and wp8 by modifying that code? If so, that's a weird regression since weinre has worked in the past on those platforms."
        Yep, that's what happened, and yes, it's a weird regression.

        And as for not needing Weinre on Android or iOS, I like the way Weinre does debugging, and I like having the same debugging interface on all of my platforms. It's also easier to set up Weinre, or it would have been if I didn't have to spend hours tracking down this bug.

        Show
        YM_Industries Joshua Walsh added a comment - "hmmm, last I remember, you could certainly use `console.log()` in iOS and Android" Perhaps I'm using an older version of those then, because I hooked window.onerror and that was the error I was getting. "the console object may well be injected into the global scope, and not available as a property of the "window" object" In JavaScript, the window object IS the global scope. testVariable = "test"; console.log(window.testVariable); //Logs "test" in the console "Could you only get weinre to work on iOS and Android and wp8 by modifying that code? If so, that's a weird regression since weinre has worked in the past on those platforms." Yep, that's what happened, and yes, it's a weird regression. And as for not needing Weinre on Android or iOS, I like the way Weinre does debugging, and I like having the same debugging interface on all of my platforms. It's also easier to set up Weinre, or it would have been if I didn't have to spend hours tracking down this bug.
        Hide
        pmuellr Patrick Mueller added a comment -

        Sergey, can you look into this? I've seen another report of funky console issues on windows - something must have changed recently relating to it.

        Show
        pmuellr Patrick Mueller added a comment - Sergey, can you look into this? I've seen another report of funky console issues on windows - something must have changed recently relating to it.
        Hide
        sgrebnov Sergey Grebnov added a comment -

        Windows Phone 8: was able to reproduce only after manually removing console object instance

        <script>
            // output errors to VS Debug window
            window.onerror = function (msg, file, line) {
                window.external.Notify("Error ::" + msg + '#' + file + '#' + line);
            };
        
            window.console = undefined; //delete window.console does not help
        </script>
        
        Weinre client script error: Error ::Unable to set property '__original' of undefined or null reference#http://10.0.8.254:8080/target/target-script-min.js#anonymous#1569
        
        

        By default window.console reports [object Console] (default VS 2012 Html5 app template w/o any scripts, etc)

        Show
        sgrebnov Sergey Grebnov added a comment - Windows Phone 8: was able to reproduce only after manually removing console object instance <script> // output errors to VS Debug window window.onerror = function (msg, file, line) { window.external.Notify( "Error ::" + msg + '#' + file + '#' + line); }; window.console = undefined; //delete window.console does not help </script> Weinre client script error: Error ::Unable to set property '__original' of undefined or null reference#http: //10.0.8.254:8080/target/target-script-min.js#anonymous#1569 By default window.console reports [object Console] (default VS 2012 Html5 app template w/o any scripts, etc)
        Hide
        githubbot ASF GitHub Bot added a comment -

        GitHub user sgrebnov opened a pull request:

        https://github.com/apache/cordova-weinre/pull/6

        CB-6991 Weinre fails to load in browsers without a built-in console

        Weinre fails to load in browsers without a built-in development console
        https://issues.apache.org/jira/browse/CB-6991

        You can merge this pull request into a Git repository by running:

        $ git pull https://github.com/sgrebnov/cordova-weinre CB-6991

        Alternatively you can review and apply these changes as the patch at:

        https://github.com/apache/cordova-weinre/pull/6.patch

        To close this pull request, make a commit to your master/trunk branch
        with (at least) the following in the commit message:

        This closes #6


        commit 198d290b5fc0b873b67e3f6c344055a9fe5611a7
        Author: sgrebnov <v-segreb@microsoft.com>
        Date: 2014-08-04T12:16:52Z

        CB-6991 Weinre fails to load in browsers without a built-in development console


        Show
        githubbot ASF GitHub Bot added a comment - GitHub user sgrebnov opened a pull request: https://github.com/apache/cordova-weinre/pull/6 CB-6991 Weinre fails to load in browsers without a built-in console Weinre fails to load in browsers without a built-in development console https://issues.apache.org/jira/browse/CB-6991 You can merge this pull request into a Git repository by running: $ git pull https://github.com/sgrebnov/cordova-weinre CB-6991 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/cordova-weinre/pull/6.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #6 commit 198d290b5fc0b873b67e3f6c344055a9fe5611a7 Author: sgrebnov <v-segreb@microsoft.com> Date: 2014-08-04T12:16:52Z CB-6991 Weinre fails to load in browsers without a built-in development console
        Hide
        sgrebnov Sergey Grebnov added a comment -

        Tested proposed fix, works fine, client can connect, core functionality works, sent pull request
        https://github.com/apache/cordova-weinre/pull/6

        Show
        sgrebnov Sergey Grebnov added a comment - Tested proposed fix, works fine, client can connect, core functionality works, sent pull request https://github.com/apache/cordova-weinre/pull/6
        Hide
        pmuellr Patrick Mueller added a comment -

        Thanks the patch Sergey; surely one of the smallest patches ever!!!

        Will try to get this integrated today.

        Show
        pmuellr Patrick Mueller added a comment - Thanks the patch Sergey; surely one of the smallest patches ever!!! Will try to get this integrated today.
        Hide
        YM_Industries Joshua Walsh added a comment -

        Thanks for the fix guys! Any idea when this will end up in NPM?

        Show
        YM_Industries Joshua Walsh added a comment - Thanks for the fix guys! Any idea when this will end up in NPM?
        Hide
        pmuellr Patrick Mueller added a comment -

        As soon as I can do a build; if you're in a pinch, and handy with git and rebuilding weinre, you should be able to build a local copy with this fix; of course, you've already hacked the same fix manually, so ... you shouldn't need anything else for yourself.

        Show
        pmuellr Patrick Mueller added a comment - As soon as I can do a build; if you're in a pinch, and handy with git and rebuilding weinre, you should be able to build a local copy with this fix; of course, you've already hacked the same fix manually, so ... you shouldn't need anything else for yourself.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 198d290b5fc0b873b67e3f6c344055a9fe5611a7 in cordova-weinre's branch refs/heads/master from sgrebnov
        [ https://git-wip-us.apache.org/repos/asf?p=cordova-weinre.git;h=198d290 ]

        CB-6991 Weinre fails to load in browsers without a built-in development console

        Show
        jira-bot ASF subversion and git services added a comment - Commit 198d290b5fc0b873b67e3f6c344055a9fe5611a7 in cordova-weinre's branch refs/heads/master from sgrebnov [ https://git-wip-us.apache.org/repos/asf?p=cordova-weinre.git;h=198d290 ] CB-6991 Weinre fails to load in browsers without a built-in development console
        Hide
        githubbot ASF GitHub Bot added a comment -

        Github user asfgit closed the pull request at:

        https://github.com/apache/cordova-weinre/pull/6

        Show
        githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/cordova-weinre/pull/6
        Hide
        pmuellr Patrick Mueller added a comment -

        Just published 2.0.0-pre-HYFXM3QM of weinre, now available at: https://www.npmjs.org/package/weinre

        Let us know if it works out for you!

        Show
        pmuellr Patrick Mueller added a comment - Just published 2.0.0-pre-HYFXM3QM of weinre, now available at: https://www.npmjs.org/package/weinre Let us know if it works out for you!
        Show
        pmuellr Patrick Mueller added a comment - Fixed in commit https://git-wip-us.apache.org/repos/asf?p=cordova-weinre.git;a=commit;h=198d290b5fc0b873b67e3f6c344055a9fe5611a7 ; tagged as 2.0.0-pre-HYFXM3QM

          People

          • Assignee:
            pmuellr Patrick Mueller
            Reporter:
            YM_Industries Joshua Walsh
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 10m
              10m
              Remaining:
              Remaining Estimate - 10m
              10m
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development