-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasync-api.js
50 lines (44 loc) · 1.1 KB
/
async-api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const log = chrome.extension.getBackgroundPage().console.log;
// tabs
async function tabsQuery(options) {
return new Promise(resolve => {
chrome.tabs.query(options, function (tabs) {
resolve(tabs);
});
});
}
async function tabsSendMessage(tabId, msg) {
return new Promise(resolve => {
chrome.tabs.sendMessage(tabId, msg, function (response) {
resolve(response);
});
})
}
async function tabsCreate(options) {
return new Promise(resolve => {
chrome.tabs.create(options, function (tab) {
resolve(tab);
});
});
}
// storage
async function storageGet(key) {
return new Promise(resolve => {
chrome.storage.sync.get(key, function (data) {
resolve(data);
});
});
}
async function storageSet(data) {
return new Promise(resolve => {
chrome.storage.sync.set(data, resolve);
});
}
// runtime
async function runtimeGetBackgroundPage() {
return new Promise(resolve => {
chrome.runtime.getBackgroundPage(function (bg) {
resolve(bg);
});
})
}