Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
chrome-call
Advanced tools
A really simple way to call the original chrome javascript API and return a Promise.
Call the Chrome JavasScript APIs then return a Promise.
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')
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>
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?
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]
})
MIT
FAQs
A really simple way to call the original chrome javascript API and return a Promise.
The npm package chrome-call receives a total of 8 weekly downloads. As such, chrome-call popularity was classified as not popular.
We found that chrome-call demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.