1
- # chrome-call
1
+ # 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 )
2
2
3
- [ ![ Build Status] ( https://img.shields.io/travis/Selection-Translator/chrome-call/master.svg?style=flat-square )] ( https://travis-ci.org/Selection-Translator/chrome-call )
4
- [ ![ 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 )
5
- [ ![ dependencies Status] ( https://img.shields.io/david/Selection-Translator/chrome-call.svg?style=flat-square )] ( https://david-dm.org/Selection-Translator/chrome-call )
6
- [ ![ devDependencies Status] ( https://img.shields.io/david/dev/Selection-Translator/chrome-call.svg?style=flat-square )] ( https://david-dm.org/Selection-Translator/chrome-call?type=dev )
7
- [ ![ NPM Version] ( https://img.shields.io/npm/v/chrome-call.svg?style=flat-square )] ( https://www.npmjs.com/package/chrome-call )
8
-
9
- Call the original chrome javascript API and return a Promise.
3
+ Call the [ Chrome JavasScript APIs] ( https://developer.chrome.com/extensions/api_index ) then return a Promise.
10
4
11
5
## Install
12
6
13
- ### Use with Webpack
7
+ ### Use with webpack
14
8
15
9
If you build your project with webpack, then you can install chrome-call from npm:
16
10
@@ -47,7 +41,7 @@ When you do:
47
41
``` js
48
42
const promise = new Promise ((resolve , reject ) => {
49
43
chrome .storage .local .get (' key' , items => {
50
- if (chrome .runtime .lastError ){
44
+ if (chrome .runtime .lastError ) {
51
45
reject (chrome .runtime .lastError )
52
46
} else {
53
47
resolve (items)
@@ -64,7 +58,7 @@ const promise = chromeCall(chrome.storage.local, 'get', 'key')
64
58
65
59
That's really simple, right?
66
60
67
- Some Chrome API methods has more than one arguments, then pass an array of params for the third argument:
61
+ Some Chrome JavaScript API methods has more than one arguments, then pass an array of params for the third argument:
68
62
69
63
``` js
70
64
chromeCall (chrome .tabs , ' sendMessage' , [tabId, message, options])
@@ -74,17 +68,16 @@ chromeCall(chrome.tabs, 'sendMessage', [tabId, message, options])
74
68
75
69
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 ) .
76
70
77
- In this situation, pass ` true ` as the fourth argument, then the value of promise will be an __ real __ Array:
71
+ In this situation, pass ` true ` as the fourth argument, then the value of promise will be an ** real ** Array:
78
72
79
73
``` js
80
74
import chromeCall from ' chrome-call'
81
75
82
- chromeCall (chrome .hid , ' receive' , connectionId, true )
83
- .then (args => {
84
- Array .isArray (args) // true
85
- const reportId = args[0 ]
86
- const data = args[1 ]
87
- })
76
+ chromeCall (chrome .hid , ' receive' , connectionId, true ).then (args => {
77
+ Array .isArray (args) // true
78
+ const reportId = args[0 ]
79
+ const data = args[1 ]
80
+ })
88
81
```
89
82
90
83
## License
0 commit comments