Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
chrome-promise-temp
Advanced tools
I'll no longer to maintain this project, please have a look to chrome-call.
Chrome API using promises.
Use npm
npm install chrome-promise
Or bower
bower install chrome-promise
Or download chrome-promise.js file.
You can include it in your HTML like this:
<script type="text/javascript" src="chrome-promise.js"></script>
Detect languages of all tabs.
chrome.promise = new ChromePromise();
chrome.promise.tabs.query({}).then(function(tabs) {
var promises = tabs.map(function(tab) {
return chrome.promise.tabs.detectLanguage(tab.id);
});
return Promise.all(promises);
}).then(function(languages) {
alert('Languages: ' + languages.join(', '));
}).catch(function(err) {
alert(err.message);
});
Use local storage.
chrome.promise = new ChromePromise();
chrome.promise.storage.local.set({foo: 'bar'}).then(function() {
alert('foo set');
return chrome.promise.storage.local.get('foo');
}).then(function(items) {
alert(JSON.stringify(items)); // => {"foo":"bar"}
});
The constructor accepts two parameters: chrome and Promise.
chrome
is the chrome API object. By default (or when null or undefined are used), it is the 'chrome' global property.
Promise
is the object used to create promises. By default, it is the 'Promise' global property.
Starting from Chrome 39, you can use generator functions. Using the methods Q.async and Q.spawn from the Q library, the previous examples can be rewritten as:
chrome.promise = new ChromePromise();
// try...catch
Q.spawn(function* () {
try {
var tabs = yield chrome.promise.tabs.query({});
var languages = yield Promise.all(tabs.map(function(tab) {
return chrome.promise.tabs.detectLanguage(tab.id);
}));
alert('Languages: ' + languages.join(', '));
} catch(err) {
alert(err);
}
});
// promise.catch
Q.async(function* () {
var tabs = yield chrome.promise.tabs.query({});
var languages = yield Promise.all(tabs.map(function(tab) {
return chrome.promise.tabs.detectLanguage(tab.id);
}));
alert('Languages: ' + languages.join(', '));
})().catch(function(err) {
alert(err);
});
Q.spawn(function* () {
yield chrome.promise.storage.local.set({foo: 'bar'});
alert('foo set');
var items = yield chrome.promise.storage.local.get('foo');
alert(JSON.stringify(items));
});
You can also use the co library instead of Q.
FAQs
DEPRECATED
The npm package chrome-promise-temp receives a total of 0 weekly downloads. As such, chrome-promise-temp popularity was classified as not popular.
We found that chrome-promise-temp 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.