# chrome-call

> A really simple way to call the original chrome javascript API and return a Promise.

Latest version **4.0.1** (published 2018-08-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install chrome-call
pnpm add chrome-call
yarn add chrome-call
bun add chrome-call
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2018-08-27 |
| First published | 2016-01-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Author | Milk Lee |
| Maintainers | milklee |
| Keywords | chrome, ext, extension, app, promise |

## Links

- npm: https://www.npmjs.com/package/chrome-call
- Repository: https://github.com/lmk123/chrome-call
- Issues: https://github.com/lmk123/chrome-call/issues
- npm.io page: https://npm.io/package/chrome-call

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 4.0.1 (latest) — 2018-08-27
- 4.0.0 — 2018-08-27
- 3.0.0 — 2017-12-21
- 2.0.0 — 2017-07-03
- 1.0.3 — 2016-10-25
- 1.0.2 — 2016-01-06
- 1.0.1 — 2016-01-05
- 1.0.0 — 2016-01-04
- 0.0.1 — 2016-01-04

## README

# chrome-call [![Build Status](https://img.shields.io/travis/Selection-Translator/chrome-call/master.svg?style=flat-square)](https://travis-ci.org/Selection-Translator/chrome-call) [![Coverage Status](https://img.shields.io/coveralls/Selection-Translator/chrome-call/master.svg?style=flat-square)](https://coveralls.io/github/Selection-Translator/chrome-call?branch=master) [![NPM Version](https://img.shields.io/npm/v/chrome-call.svg?style=flat-square)](https://www.npmjs.com/package/chrome-call)

Call the [Chrome JavasScript APIs](https://developer.chrome.com/extensions/api_index) then return a Promise.

## Install

### Use with webpack

If you build your project with webpack, then you can install chrome-call from npm:

```
npm install chrome-call
```

then you can import it in your project:

```js
// es6
import chromeCall from 'chrome-call'

// commonjs
const chromeCall = require('chrome-call')
```

### Use with &lt;script&gt;

Download chrome-call.js from [unpkg](https://unpkg.com/chrome-call)([min version](https://unpkg.com/chrome-call/dist/chrome-call.min.js)), then reference it in your html:

```html
<script src="path/to/chrome-call.js"></script>
<!-- now you will get a global variable named chromeCall -->
<script>
  typeof chromeCall // function
</script>
```

## Usage

When you do:

```js
const promise = new Promise((resolve, reject) => {
  chrome.tabs.sendMessage(tabId, message, options, response => {
    if (chrome.runtime.lastError) {
      reject(chrome.runtime.lastError)
    } else {
      resolve(response)
    }
  })
})
```

It's equal to:

```js
const promise = chromeCall(chrome.tabs, 'sendMessage', tabId, message, options)
```

That's really simple, right?

### Multiple arguments in callback

Most of chrome API only has zero or one argument in callback, but someone not, such as [chrome.hid.receive](https://developer.chrome.com/apps/hid#method-receive).

In this situation, pass `true` as the first argument, then the value of promise will be an **real** Array:

```js
import chromeCall from 'chrome-call'

chromeCall(true, chrome.hid, 'receive', connectionId).then(args => {
  Array.isArray(args) // true
  const reportId = args[0]
  const data = args[1]
})
```

## License

MIT

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