Skip to content

debug.enable() fails since debug() is a native function in Chrome #153

Closed

Description

@ibc

README says:

Debug works in the browser as well, currently persisted by localStorage. For example if you have worker:a and worker:b as shown below, and wish to debug both type debug.enable('worker:*') in the console and refresh the page

Obviously running this command fails because debug is a native, and deprecated, function in Chrome (while it doe snot exist in Firefox).

So, how to use debug in the browser? should I include the library in the window namespace to make it available from the console?

Activity

  1. TooTallNate commented on Nov 5, 2014

    @TooTallNate
    Contributor

    Are you actually trying it?
    I've never seemed to have any problems in Chrome.

  2. ibc commented on Nov 5, 2014

    @ibc
    ContributorAuthor

    Actually it works if my JS app exposes debug as an internal accessor:

    var MyApp = {
      debug: require('debug'),
      xxxx: require(....)
    };
    
    module.exports = MyApp;
    

    Then browserify -s MyApp and load the bundle script in my page, so I can run in the browser console:

    MyApp.debug.enable('MyApp:*');
    

    This works, really :)

    But if my JS app exposes the 'debug' module in the 'window' namespace then I'm overriding the debug() method (deprecated) that Chrome provides:

    > debug
    function debug(fn) { [Command Line API] }
    

    I have no idea what that is and what that does.

    BTW, the README says:

    type debug.enable('worker:*') in the console

    but for that to work I need to expose the 'debug' module in the 'window' namespace, or do I miss something?

  3. TooTallNate commented on Nov 5, 2014

    @TooTallNate
    Contributor

    But if my JS app exposes the 'debug' module in the 'window' namespace then I'm overriding the debug() method (deprecated) that Chrome provides:

    Are you literally doing? This seems to work for me:

    window.debug = require('debug');

    BTW, the README says:

    type debug.enable('worker:*') in the console

    but for that to work I need to expose the 'debug' module in the 'window' namespace, or do I miss something?

    The README comment is assuming that you're using the standalone debug.js file in the dist dir.

    It's assumed that if you're browserifying yourself, then you can figure out how to expose the variable in a manner appropriate for your app.

  4. ibc commented on Nov 5, 2014

    @ibc
    ContributorAuthor

    Clear. I'm not using the standalone debug.js but instead browserifying my own app, which internally requires('debug').

    Just a final question: If my app includes different libraries and those libraries internally require 'debug' module, and then I also load the standalone debug.js in my web, would window.debug be the same object as MyApp.debug and MyApp.someLibrary.debug?

  5. TooTallNate commented on Nov 5, 2014

    @TooTallNate
    Contributor

    It depends really. Ideally, yes, would be the answer. But in reality, if there's multiple copies of the debug module within your node_modules directory, then there's a possibility that require('debug') calls in different module would return different objects.

    You can use npm dedup, and check to make sure all modules are using compatible versions of debug, in order to avoid that situation.

  6. ibc commented on Nov 5, 2014

    @ibc
    ContributorAuthor

    Clear. Thanks a lot.
    (I'll close this issue as it is not an issue at the end)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions