npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

global-event-handlers-map

v1.0.2

Published

GlobalEventHandlers mapped out completely cross browsers

Downloads

9

Readme

global-event-handlers

GlobalEventHandlers mapped out completely - cross browsers

Using this powerful little tool will map out for you all Global Event Handlers in any browser you'd wish to execute it on.

installation

npm install global-event-handlers-map --save

usage

const getGlobalEventHandlersMap = require('global-event-handlers-map');

const gehsMap = getGlobalEventHandlersMap();

output

a map of all global event listeners in the browser in the following format:

{
    'OBJECT': [
        'onEVENT1',
        'onEVENT2',
        'onEVENT3'
    ]
}

example

const getGlobalEventHandlersMap = require('global-event-handlers-map');

const webSocketGEHsMap = getGlobalEventHandlersMap('WebSocket');

(webSocketGEHsMap == {
  "WebSocket": [
    "onopen",
    "onerror",
    "onclose",
    "onmessage"
  ] // results in true
});

here's an example of how to register with your own listener to every global event handler that exists on window!


const windowGEHsMap = getGlobalEventHandlersMap('window')['window'];

for (let i = 0; i < windowGEHsMap.length; i++) {
  const geh = windowGEHsMap[i];
  window[geh] = (event) => { console.log(event) });
}

options

  1. filter (first optional argument)

allows you to pass a string that must exist within the object in order for it to make it to the final result map:

const getGlobalEventHandlersMap = require('global-event-handlers-map');

const gehsMap = getGlobalEventHandlersMap('*'); // will return a non-filtered map
const gehsMap = getGlobalEventHandlersMap('HTML'); // will return a map that only contains objects that contain the string 'HTML' (such as 'HTMLBodyElement')
const gehsMap = getGlobalEventHandlersMap('Doc'); // will return a map that only contains objects that contain the string 'Doc' (such as 'Document')

default value: '*'

  1. hasOwnProperty (second optional argument)

allows you to pass a boolean that indicates whether iterated object must has iterated property as its own property or not:

const getGlobalEventHandlersMap = require('global-event-handlers-map');

const gehsMap = getGlobalEventHandlersMap('*', true); // will return a map with objects and global event handlers properties that are the object's own properties
const gehsMap = getGlobalEventHandlersMap('*', false); // will return a map with objects and global event handlers properties - whether the properties are the object's own properties or not

default value: true

  1. noEmptyArrays (third optional argument)

allows you to pass a boolean that indicates whether final result object should contain objects that have zero global event handlers or not:

const getGlobalEventHandlersMap = require('global-event-handlers-map');

const gehsMap = getGlobalEventHandlersMap('*', true, true); // will return a map with objects and global event handlers properties only if the object even has any global event handlers
const gehsMap = getGlobalEventHandlersMap('*', true, false); // will return a map with objects and global event handlers properties whether the object has any global event handlers or not

default value: false

  1. debug (fourth optional argument)

allows you to pass a boolean that indicates whether to run module in debug mode or not. debug mode just logs errors in case any are thrown:

const getGlobalEventHandlersMap = require('global-event-handlers-map');

const gehsMap = getGlobalEventHandlersMap('*', true, true, true); // will run in debug mode
const gehsMap = getGlobalEventHandlersMap('*', true, false, false); // will not run in debug mode

default value: false

contribution

in addition to this project there is a website that should show the global event handlers map of every (os + browser) combination that ever existed. in reality however, it shows most of the existing combinations, but not all of them. the maps were extracted using every existing combination in browserstack, but even in browserstack many automatic combinations have failed. also, the extraction script is not automatic and does not run every time there's a new browser/os. contributing to the JSON could help a lot with maintaining the map and keeping it as updated and as accurate as possible. highly appreciated!