You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 18, 2021. It is now read-only.
A really simple way to call the original chrome javascript API and return a Promise.
@@ -19,21 +19,21 @@ npm i -S chrome-call
19
19
When you do:
20
20
21
21
```js
22
-
var promise =newPromise(function(resolve,reject) {
23
-
chrome.storage.local.get('key',function(items) {
22
+
var promise =newPromise(function(resolve,reject) {
23
+
chrome.storage.local.get('key',function(items) {
24
24
if(chrome.runtime.lastError){
25
-
reject(chrome.runtime.lastError);
26
-
}else{
27
-
resolve(items);
25
+
reject(chrome.runtime.lastError)
26
+
}else{
27
+
resolve(items)
28
28
}
29
-
});
30
-
});
29
+
})
30
+
})
31
31
```
32
32
33
33
It's equal to:
34
34
35
35
```js
36
-
var promise =chromeCall('storage.local.get','key');
36
+
var promise =chromeCall('storage.local.get','key')
37
37
```
38
38
39
39
That's really simple, right?
@@ -42,24 +42,24 @@ That's really simple, right?
42
42
43
43
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).
44
44
45
-
In this situation, pass `true` as the first argument, then the value of promise will be an (real) Array:
45
+
In this situation, pass `true` as the first argument, then the value of promise will be an __real__ Array:
46
46
47
47
```js
48
-
chromeCall(true,'hid.receive',connectionId)
49
-
.then(function(args){
50
-
Array.isArray(args);// true
51
-
var reportId = args[0];
52
-
var data = args[1];
53
-
});
48
+
chromeCall(true,'hid.receive',connectionId)
49
+
.then(function(args){
50
+
Array.isArray(args) // true
51
+
var reportId = args[0]
52
+
var data = args[1]
53
+
})
54
54
```
55
55
56
56
### Scope
57
57
58
58
The global `chromeCall` search function on `window.chrome`, but you can use different scope:
59
59
60
60
```js
61
-
var local =chromeCall.scope('storage.local');// or chromeCall.scope(chrome.storage.local)
62
-
var promise =local('get','key');
61
+
var local =chromeCall.scope('storage.local') // or chromeCall.scope(chrome.storage.local)
0 commit comments