Software

Monitor Events and Function Calls via Console


Despite having worked on the very complex Firefox for a number of years, I’ll always love plain old console.log debugging. Logging can provide an audit trail as events happen and text you can share with others. Did you know that chrome provides monitorEvents and monitor so that you can get a log each time an event occurs or function is called?

Contents

Monitor Events

Pass an element and a series of events to monitorEvents to get a console log when the event happens:

// Monitor any clicks within the window
monitorEvents(window, 'click')

// Monitor for keyup and keydown events on the body
monitorEvents(document.body, ['keyup', 'keydown'])

You can pass an array of events to listen for multiple events. The logged event represents the same event you’d see if you manually called addEventListener.

Monitor Function Calls

The monitor method allows you to listen for calls on a specific function:

// Define a sample function
function myFn() { }
// Monitor it
monitor(myFn)

// Usage 1: Basic call
myFn()
// function myFn called

// Usage 2: Arguments
myFn(1)
// function myFn called with arguments: 1

I really like that you can the arguments provided, which is great for inspecting.

I usually opt for logpoints instead of embedding console statements in code, but monitor and monitorEvents provide an alternative to both.

  • 6 Things You Didn’t Know About Firefox OS

    Firefox OS is all over the tech news and for good reason:  Mozilla’s finally given web developers the platform that they need to create apps the way they’ve been creating them for years — with CSS, HTML, and JavaScript.  Firefox OS has been rapidly improving…

  • Animated 3D Flipping Menu with CSS
  • Editable Content Using MooTools 1.2, PHP, and MySQL

    Everybody and their aerobics instructor wants to be able to edit their own website these days. And why wouldn’t they? I mean, they have a $500 budget, no HTML/CSS experience, and extraordinary expectations. Enough ranting though. Having a website that allows for…

  • Sara Soueidan’s Favorite CodePen Demos


Source link
Show More

admin

Makes Noise is a blog where you can find all the juicy details on a variety of topics including health and fitness, technology, lifestyle, entertainment, love and relationships, beauty and makeup, sports and so much more. The blog is updated regularly to make sure you have all the latest and greatest information on the topics that matter most to you.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button