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

electron-microscope

v2.0.0

Published

Use electron to inspect websites and extract data. useful for automation, testing, web scraping, etc

Downloads

5

Readme

electron-microscope

Use electron to inspect websites and extract data. Intended for automation, testing, web scraping, etc.

Loads urls inside an electron webview tag, allows you to execute code on them, and stream data from the pages back to your main process.

Run this headlessly on Linux using xvfb-run.

BETA DISCLAIMER early adopters only, this module is still hecka fresh

usage

Use this in an electron app:

var electron = require('electron')
var createMicroscope = require('electron-microscope')

electron.app.on('ready', function () {
  createMicroscope(function (err, scope) {
    if (err) throw err
    // use your new microscope
  })
}) 

Run it with electron:

$ npm install electron-prebuilt -g
$ electron my-code.js

API

require('electron-microscope')(options, ready)

Requiring the module returns a constructor function that you use to create a new instance. Pass it an options object and a ready callback that will be called with (error, scope). scope is your new instance all ready to go.

scope.loadURL(url, cb)

Load a url, and call cb with (err) when loading is done. If there was a problem loading the page err will be the error, otherwise it means it loaded successfully

scope.run(code)

Run code the currently loaded page. Run this after calling loadURL. Code must be a string, if it is a function then .toString() will be called on it. scope.run returns a readable stream that emits data generated by your code.

You code must be a function that has this template:

function (send, done) {
  // put your custom code here
  // call 'send(data)' to write data to the stream
  // call 'done()' to end the stream
  // calling send is optional, but you must eventually call done
}

For example:

var scraper = `function (send, done) {
  for (var i = 0; i < 5; i++) send(i)
  done()
}`
var output = scope.run(scraper)
output.pipe(concat(function (out) {
  console.log(out.toString()) // 12345
}))

scope.on('will-navigate', cb)

Emitted the page wants to start navigation. It can happen when the window.location object is changed or a link is clicked in the page.

Calls cb with (url), forwarded from this event.

scope.on('did-start-loading', cb)

Corresponds to the points in time when the spinner of the tab starts spinning.

Calls cb with no arguments, forwarded from this event.

scope.on('did-stop-loading', cb)

Corresponds to the points in time when the spinner of the tab stops spinning.

Calls cb with no arguments, forwarded from this event.

scope.destroy()

Call when you don't want to use the scope anymore. Causes the browser-window elecron-microscope uses internally to close.