webext-schema 4.2.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/modules/browser.js +79 -49
- package/package.json +1 -1
package/modules/browser.js
CHANGED
|
@@ -35,14 +35,14 @@ export const createBookmark = async opt => {
|
|
|
35
35
|
const { bookmarks } = browser;
|
|
36
36
|
node = await bookmarks.create(opt);
|
|
37
37
|
}
|
|
38
|
-
return node
|
|
38
|
+
return node ?? null;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* get bookmark tree node
|
|
43
43
|
*
|
|
44
44
|
* @param {string|Array} id - bookmark ID or array of bookmark IDs
|
|
45
|
-
* @returns {Array} - array of bookmarks.BookmarkTreeNode
|
|
45
|
+
* @returns {?Array} - array of bookmarks.BookmarkTreeNode
|
|
46
46
|
*/
|
|
47
47
|
export const getBookmarkTreeNode = async id => {
|
|
48
48
|
const isGranted = await isPermissionGranted({
|
|
@@ -59,7 +59,7 @@ export const getBookmarkTreeNode = async id => {
|
|
|
59
59
|
res = await bookmarks.getTree();
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
return res
|
|
62
|
+
return res ?? null;
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
/* browserSettings */
|
|
@@ -77,7 +77,7 @@ export const getCloseTabsByDoubleClickValue = async () => {
|
|
|
77
77
|
const { browserSettings: { closeTabsByDoubleClick } } = browser;
|
|
78
78
|
userValue = await closeTabsByDoubleClick.get({});
|
|
79
79
|
}
|
|
80
|
-
return userValue
|
|
80
|
+
return userValue ?? null;
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
/**
|
|
@@ -135,7 +135,7 @@ export const getNewTabPositionValue = async () => {
|
|
|
135
135
|
const { browserSettings: { newTabPosition } } = browser;
|
|
136
136
|
res = await newTabPosition.get({});
|
|
137
137
|
}
|
|
138
|
-
return res
|
|
138
|
+
return res ?? null;
|
|
139
139
|
};
|
|
140
140
|
|
|
141
141
|
/* commands */
|
|
@@ -185,7 +185,7 @@ export const updateCommand = async (id, value = '') => {
|
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
-
return func
|
|
188
|
+
return func ?? null;
|
|
189
189
|
};
|
|
190
190
|
|
|
191
191
|
/* contextualIdentities */
|
|
@@ -201,13 +201,9 @@ export const getAllContextualIdentities = async () => {
|
|
|
201
201
|
let arr;
|
|
202
202
|
if (isGranted) {
|
|
203
203
|
const { contextualIdentities } = browser;
|
|
204
|
-
|
|
205
|
-
arr = await contextualIdentities.query({});
|
|
206
|
-
} catch (e) {
|
|
207
|
-
logErr(e);
|
|
208
|
-
}
|
|
204
|
+
arr = await contextualIdentities.query({});
|
|
209
205
|
}
|
|
210
|
-
return arr
|
|
206
|
+
return arr ?? null;
|
|
211
207
|
};
|
|
212
208
|
|
|
213
209
|
/**
|
|
@@ -226,13 +222,9 @@ export const getContextualId = async cookieStoreId => {
|
|
|
226
222
|
let id;
|
|
227
223
|
if (isGranted) {
|
|
228
224
|
const { contextualIdentities } = browser;
|
|
229
|
-
|
|
230
|
-
id = await contextualIdentities.get(cookieStoreId);
|
|
231
|
-
} catch (e) {
|
|
232
|
-
logErr(e);
|
|
233
|
-
}
|
|
225
|
+
id = await contextualIdentities.get(cookieStoreId);
|
|
234
226
|
}
|
|
235
|
-
return id
|
|
227
|
+
return id ?? null;
|
|
236
228
|
};
|
|
237
229
|
|
|
238
230
|
/* management */
|
|
@@ -248,17 +240,12 @@ export const getEnabledTheme = async () => {
|
|
|
248
240
|
let res;
|
|
249
241
|
if (isGranted) {
|
|
250
242
|
const { management } = browser;
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
res =
|
|
255
|
-
arr.filter(info => info?.type === 'theme' && info?.enabled && info);
|
|
256
|
-
}
|
|
257
|
-
} catch (e) {
|
|
258
|
-
logErr(e);
|
|
243
|
+
const arr = await management.getAll();
|
|
244
|
+
if (Array.isArray(arr) && arr.length) {
|
|
245
|
+
res = arr.filter(info => info?.type === 'theme' && info?.enabled && info);
|
|
259
246
|
}
|
|
260
247
|
}
|
|
261
|
-
return res
|
|
248
|
+
return res ?? null;
|
|
262
249
|
};
|
|
263
250
|
|
|
264
251
|
/**
|
|
@@ -279,13 +266,13 @@ export const getExtensionInfo = async id => {
|
|
|
279
266
|
const { management } = browser;
|
|
280
267
|
ext = await management.get(id);
|
|
281
268
|
}
|
|
282
|
-
return ext
|
|
269
|
+
return ext ?? null;
|
|
283
270
|
};
|
|
284
271
|
|
|
285
272
|
/**
|
|
286
273
|
* get external extensions
|
|
287
274
|
*
|
|
288
|
-
* @returns {?Array} -array of management.extensionInfo
|
|
275
|
+
* @returns {?Array|boolean} -array of management.extensionInfo
|
|
289
276
|
*/
|
|
290
277
|
export const getExternalExtensions = async () => {
|
|
291
278
|
const isGranted = await isPermissionGranted({
|
|
@@ -294,17 +281,12 @@ export const getExternalExtensions = async () => {
|
|
|
294
281
|
let res;
|
|
295
282
|
if (isGranted) {
|
|
296
283
|
const { management } = browser;
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
res =
|
|
301
|
-
arr.filter(info => info?.type === 'extension' && info);
|
|
302
|
-
}
|
|
303
|
-
} catch (e) {
|
|
304
|
-
logErr(e);
|
|
284
|
+
const arr = await management.getAll();
|
|
285
|
+
if (Array.isArray(arr) && arr.length) {
|
|
286
|
+
res = arr.filter(info => info?.type === 'extension' && info);
|
|
305
287
|
}
|
|
306
288
|
}
|
|
307
|
-
return res
|
|
289
|
+
return res ?? null;
|
|
308
290
|
};
|
|
309
291
|
|
|
310
292
|
/* notifications */
|
|
@@ -326,7 +308,7 @@ export const clearNotification = async id => {
|
|
|
326
308
|
const { notifications } = browser;
|
|
327
309
|
func = notifications.clear(id);
|
|
328
310
|
}
|
|
329
|
-
return func
|
|
311
|
+
return func ?? null;
|
|
330
312
|
};
|
|
331
313
|
|
|
332
314
|
/**
|
|
@@ -351,7 +333,7 @@ export const createNotification = async (id, opt) => {
|
|
|
351
333
|
}
|
|
352
334
|
func = notifications.create(id, opt);
|
|
353
335
|
}
|
|
354
|
-
return func
|
|
336
|
+
return func ?? null;
|
|
355
337
|
};
|
|
356
338
|
|
|
357
339
|
/* permissions */
|
|
@@ -487,7 +469,55 @@ export const sendMessage = async (id, msg, opt) => {
|
|
|
487
469
|
func = runtime.sendMessage(msg, opt);
|
|
488
470
|
}
|
|
489
471
|
}
|
|
490
|
-
return func
|
|
472
|
+
return func ?? null;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
/* scripting */
|
|
476
|
+
/**
|
|
477
|
+
* is scripting available
|
|
478
|
+
*
|
|
479
|
+
* @returns {boolean} - result
|
|
480
|
+
*/
|
|
481
|
+
export const isScriptingAvailable = async () => {
|
|
482
|
+
const isGranted = await isPermissionGranted({
|
|
483
|
+
permissions: ['scripting']
|
|
484
|
+
});
|
|
485
|
+
let res;
|
|
486
|
+
if (isGranted) {
|
|
487
|
+
const { scripting } = browser;
|
|
488
|
+
res = typeof scripting?.executeScript === 'function';
|
|
489
|
+
}
|
|
490
|
+
return !!res;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* execute script to tab
|
|
495
|
+
*
|
|
496
|
+
* @param {object} opt - options
|
|
497
|
+
* @returns {?Array|boolean} - array of InjectionResult object
|
|
498
|
+
*/
|
|
499
|
+
export const executeScriptToTab = async (opt = {}) => {
|
|
500
|
+
const { args, injectImmediately, files, func, target } = opt;
|
|
501
|
+
const isGranted = await isScriptingAvailable();
|
|
502
|
+
let fn;
|
|
503
|
+
if (isGranted && Number.isInteger(target?.tabId)) {
|
|
504
|
+
const { scripting } = browser;
|
|
505
|
+
if (Array.isArray(files) && files.length) {
|
|
506
|
+
fn = scripting.executeScript({
|
|
507
|
+
files,
|
|
508
|
+
target,
|
|
509
|
+
injectImmediately: !!injectImmediately
|
|
510
|
+
});
|
|
511
|
+
} else if (typeof func === 'function') {
|
|
512
|
+
fn = scripting.executeScript({
|
|
513
|
+
func,
|
|
514
|
+
target,
|
|
515
|
+
args: Array.isArray(args) ? args : null,
|
|
516
|
+
injectImmediately: !!injectImmediately
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return fn ?? null;
|
|
491
521
|
};
|
|
492
522
|
|
|
493
523
|
/* search */
|
|
@@ -543,7 +573,7 @@ export const getRecentlyClosedTab = async windowId => {
|
|
|
543
573
|
}
|
|
544
574
|
}
|
|
545
575
|
}
|
|
546
|
-
return tab
|
|
576
|
+
return tab ?? null;
|
|
547
577
|
};
|
|
548
578
|
|
|
549
579
|
/**
|
|
@@ -568,7 +598,7 @@ export const getSessionWindowValue = async (key, windowId) => {
|
|
|
568
598
|
const { sessions } = browser;
|
|
569
599
|
value = await sessions.getWindowValue(windowId, key);
|
|
570
600
|
}
|
|
571
|
-
return value
|
|
601
|
+
return value ?? null;
|
|
572
602
|
};
|
|
573
603
|
|
|
574
604
|
/**
|
|
@@ -589,7 +619,7 @@ export const restoreSession = async sessionId => {
|
|
|
589
619
|
const { sessions } = browser;
|
|
590
620
|
ses = await sessions.restore(sessionId);
|
|
591
621
|
}
|
|
592
|
-
return ses
|
|
622
|
+
return ses ?? null;
|
|
593
623
|
};
|
|
594
624
|
|
|
595
625
|
/**
|
|
@@ -650,7 +680,7 @@ export const getAllStorage = async (area = 'local') => {
|
|
|
650
680
|
const { storage } = browser;
|
|
651
681
|
data = await storage[area]?.get();
|
|
652
682
|
}
|
|
653
|
-
return data
|
|
683
|
+
return data ?? null;
|
|
654
684
|
};
|
|
655
685
|
|
|
656
686
|
/**
|
|
@@ -670,7 +700,7 @@ export const getStorage = async (key, area = 'local') => {
|
|
|
670
700
|
const { storage } = browser;
|
|
671
701
|
data = await storage[area]?.get(key);
|
|
672
702
|
}
|
|
673
|
-
return data
|
|
703
|
+
return data ?? null;
|
|
674
704
|
};
|
|
675
705
|
|
|
676
706
|
/**
|
|
@@ -823,7 +853,7 @@ export const execScriptsToTabInOrder = async (tabId, opts = []) => {
|
|
|
823
853
|
const { value } = await Promise.allSettled(func).then(a => a.pop());
|
|
824
854
|
res = value;
|
|
825
855
|
}
|
|
826
|
-
return res
|
|
856
|
+
return res ?? null;
|
|
827
857
|
};
|
|
828
858
|
|
|
829
859
|
/**
|
|
@@ -948,7 +978,7 @@ export const moveTab = async (tabId, opt) => {
|
|
|
948
978
|
if (arr && !Array.isArray(arr)) {
|
|
949
979
|
arr = [arr];
|
|
950
980
|
}
|
|
951
|
-
return arr
|
|
981
|
+
return arr ?? null;
|
|
952
982
|
};
|
|
953
983
|
|
|
954
984
|
/**
|
|
@@ -1047,7 +1077,7 @@ export const getCurrentTheme = async () => {
|
|
|
1047
1077
|
const { theme } = browser;
|
|
1048
1078
|
currentTheme = await theme.getCurrent();
|
|
1049
1079
|
}
|
|
1050
|
-
return currentTheme
|
|
1080
|
+
return currentTheme ?? null;
|
|
1051
1081
|
};
|
|
1052
1082
|
|
|
1053
1083
|
/* windows */
|
package/package.json
CHANGED