# electron-microscope

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

Latest version **2.0.0** (published 2016-02-13) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install electron-microscope
pnpm add electron-microscope
yarn add electron-microscope
bun add electron-microscope
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2016-02-13 |
| First published | 2016-02-13 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 154 |
| Maintainers | maxogden |

## Links

- npm: https://www.npmjs.com/package/electron-microscope
- Repository: https://github.com/maxogden/electron-microscope
- Homepage: https://github.com/maxogden/electron-microscope#readme
- Issues: https://github.com/maxogden/electron-microscope/issues
- npm.io page: https://npm.io/package/electron-microscope

## Dependencies (3)

- [domify](https://npm.io/package/domify.md) ^1.4.0
- [inherits](https://npm.io/package/inherits.md) ^2.0.1
- [through2](https://npm.io/package/through2.md) ^2.0.1

## Recent versions

- 2.0.0 (latest) — 2016-02-13

## README

# electron-microscope

Use [electron](http://electron.atom.io/) to inspect websites and extract data. Intended for automation, testing, web scraping, etc.

Loads urls inside an electron [webview tag](https://github.com/atom/electron/blob/master/docs/api/web-view-tag.md), 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:

```js
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:

```sh
$ 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:

```js
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:

```js
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](https://github.com/atom/electron/blob/master/docs/api/web-view-tag.md#event-will-navigate).

### 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](https://github.com/atom/electron/blob/master/docs/api/web-view-tag.md#event-did-start-loading).

### 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](https://github.com/atom/electron/blob/master/docs/api/web-view-tag.md#event-did-stop-loading).

### scope.destroy()

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

---
_Source: https://npm.io/package/electron-microscope · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
