Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chrome-call

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chrome-call

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

  • 4.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
increased by166.67%
Maintainers
1
Weekly downloads
 
Created
Source

chrome-call Build Status Coverage Status NPM Version

Call the Chrome JavasScript APIs 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:

// es6
import chromeCall from 'chrome-call'

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

Use with <script>

Download chrome-call.js from unpkg(min version), then reference it in your 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:

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:

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.

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

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

Keywords

FAQs

Package last updated on 27 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc