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

inspector

v0.5.0

Published

Node.js binding for WebKit Inspector API

Downloads

4,193

Readme

Inspector

npm npm downloads

Node.js binding for WebKit Inspector API

Example

var inspector = require('inspector');

var inspect = inspector(9222, '127.0.0.1', 'about:blank', function () {
    inspect.Page.enable(function (error) {
        if (error) throw error;

        inspect.Page.once('loadEventFired', function (response) {
            
            // window.onload emitted at this time `timestamp`:
            console.log(new Date(response.timestamp));
        });
    });
});

Generating the Library & Documentation

The code and documentation is generated from the WebKit repository's debugger protocol specification files. NOTE: it's probably a good idea to remove the old files in doc/ and lib/ before regenerating them. To generate the code & docs, run:

$ npm run generate

API documetation

inspect = inspector(port, host, href, [callback])

To connect a remote WebKit inspector you must first start the WebKit instance with the remote debugger enabled. In Chrome this is done by adding the --remote-debugging-port=9222 process argument.

The inspector module will then try to connect to http://127.0.0.1:9222/json if a connection coundn't be made within 2 seconds, it will emit and error event.

Besides from the remote port and host you will also need to spefic the href of the page that the inspector should connect to. Note that the page must already be open, before the inspector module can connect to it.

The optional callback is executed once the connect event emits. It will therefor only executeif a connection could be established successfully.

var inspector = require('inspector');

var inspect = inspector(9222, '127.0.0.1', 'about:blank', function () {
    // connected
});

inspect.close([callback])

Will close the WebSocket connection or stop the inspector from atempting to make a connection.

Once everything is closed the close event will emit.

The optional callback is executed once the close event emits.

inspect.close(function () {
    // inspector closed
});

inspect[domain]

The WebKit Inspector is splited up intro subparts (called domains).

All WebKit Inspector domains are documented in the doc directory.

inspect[domain][command](parameters [...], callback)

Commands are executed by by adding a [command] to the domain object, and then call it by adding parameters and callback as descibed in the documentation.

The callback is executed with an error argument there is either null or an Error type. The second argument is a response object.

Note that not all commands returns a response object.

Example where the document title is returned:

inspect.Runtime.evaluate("document.title;", function (error, response) {
    if (error) throw error;

    // contains the document title
    console.log(response.result.value);
});

inspect[domain].on(eventname, callback)

The WebKit Inspector emits a lot of events, all events are associated with a domain and are therefore only emitted on a domain object.

The event handler is only emitted with a single parameter, there is a object containing properties as described in the documentation.

Example on how to listen on the loadEventFired, note that you must call Page.enable() first.

inspect.Page.once('loadEventFired', function (response) {
    
    // window.onload emitted at this time `timestamp`:
    console.log(new Date(response.timestamp));
});

Note: if the event isn't supported the inspector module will throw.

Event: connect

Emitted once a connection is successfully established.

Event: close

Emitted once all connections are closed. This is usually after inspect.close() is called, but if the server closed the connection this event will also emit.

Once the close event has emitted the inspect.closed flag becomes true.

Event: error

Emiited in case any error occurred. Note if you don't listen to this event the error will be thrown.