# page-evaluate

> Monitor web pages for changes

Latest version **1.1.0** (published 2022-11-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install page-evaluate
pnpm add page-evaluate
yarn add page-evaluate
bun add page-evaluate
```

## Health

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

Positive: no vulnerabilities; high maintenance score.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-11-12 |
| First published | 2020-05-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Adam Quinton |
| Maintainers | zvakanaka |
| Keywords | change, changed, changes, diff, notify, price, site |

## Links

- npm: https://www.npmjs.com/package/page-evaluate
- Repository: https://github.com/zvakanaka/page-evaluate
- Homepage: https://github.com/zvakanaka/page-evaluate#readme
- Issues: https://github.com/zvakanaka/page-evaluate/issues
- npm.io page: https://npm.io/package/page-evaluate

## Dependencies (2)

- [jsdom](https://npm.io/package/jsdom.md) ^20.0.2
- [body-snatchers](https://npm.io/package/body-snatchers.md) ^1.2.0

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2022-11-12
- 1.0.0 — 2020-05-13

## README

Monitor web pages for changes from Node.js

# Examples
 * [Price Change](./examples/price.md)
 * [New List Item](./examples/list.md)

# Window
Get the [jsdom](https://github.com/jsdom/jsdom) `window` object for a web page.

```javascript
const { window } = require('page-evaluate');
```

## Callback
```javascript
window(
  'https://example.com',
  function ({ document }) { // callback function
    const result = document.querySelector('h1').textContent;
    console.log(result); // logs 'Example Domain'
  }
);
```

## Promise
```javascript
window('https://example.com').then(({ document }) => {
  const result = document.querySelector('h1').textContent;
  console.log(result); // logs 'Example Domain'
});
```
## Async/Await
```javascript
const { document } = await window('https://example.com');
const result = document.querySelector('h1').textContent;
console.log(result); // logs 'Example Domain'
```
# Evaluate JavaScript
Evaluates a string of JavaScript on a web page and returns the output.

> Note: Sanitize any input, but this is safe - "fresh copies of all the JavaScript spec-provided globals [are] installed on window" - [jsdom readme](https://github.com/jsdom/jsdom#executing-scripts)

```javascript
const { evaluate } = require('page-evaluate');
```

## Callback
```javascript
evaluate(
  'https://example.com',
  `document.querySelector('h1').textContent`,
  function (result) { // callback function
    console.log(result); // logs 'Example Domain'
  }
);
```
## Promise
```javascript
evaluate('https://example.com',`document.querySelector('h1').textContent`)
  .then((result) => {
    console.log(result); // logs 'Example Domain'
  });
```

## Async/Await
```javascript
const result = await evaluate('https://example.com',
  `document.querySelector('h1').textContent`);

console.log(result); // logs 'Example Domain'
```

# Run Your Program on a Schedule with a Cron Job
Send an [email](./examples/list.md), turn on a light, etc. when a web page changes.
1) Get the path of [Node.js](https://github.com/nvm-sh/nvm#install--update-script) on your system with `$ which node`

2) Edit your cron jobs with: `$ crontab -e`  
(replace `/path/to/node` with the output from step 1)
```bash
NODE_PATH=/path/to/node

# Every 30 minutes (between 7am and 7pm, Mon-Sat)
*/30 7-19 * * 1-6 $NODE_PATH index.js >> /path/to/log.txt
<Put a new line at the end or it will not work>
```

> See [crontab.guru](https://crontab.guru/) for help and examples

# Dependencies
* [body-snatchers](https://github.com/zvakanaka/body-snatchers) (uses either [puppeteer](https://github.com/puppeteer/puppeteer/) or [node-fetch](https://github.com/node-fetch/node-fetch) to get pages)
* [jsdom](https://github.com/jsdom/jsdom)

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