webextension-messages 1.0.0 → 1.0.1

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.
@@ -0,0 +1,1427 @@
1
+ /******/ (() => { // webpackBootstrap
2
+ /******/ var __webpack_modules__ = ({
3
+
4
+ /***/ "./node_modules/webextension-polyfill/dist/browser-polyfill.js"
5
+ /*!*********************************************************************!*\
6
+ !*** ./node_modules/webextension-polyfill/dist/browser-polyfill.js ***!
7
+ \*********************************************************************/
8
+ (module, exports) {
9
+
10
+ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) {
11
+ if (true) {
12
+ !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
13
+ __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
14
+ (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
15
+ __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
16
+ } else // removed by dead control flow
17
+ { var mod; }
18
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (module) {
19
+ /* webextension-polyfill - v0.12.0 - Tue May 14 2024 18:01:29 */
20
+ /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
21
+ /* vim: set sts=2 sw=2 et tw=80: */
22
+ /* This Source Code Form is subject to the terms of the Mozilla Public
23
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
24
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
25
+ "use strict";
26
+
27
+ if (!(globalThis.chrome && globalThis.chrome.runtime && globalThis.chrome.runtime.id)) {
28
+ throw new Error("This script should only be loaded in a browser extension.");
29
+ }
30
+ if (!(globalThis.browser && globalThis.browser.runtime && globalThis.browser.runtime.id)) {
31
+ const CHROME_SEND_MESSAGE_CALLBACK_NO_RESPONSE_MESSAGE = "The message port closed before a response was received.";
32
+
33
+ // Wrapping the bulk of this polyfill in a one-time-use function is a minor
34
+ // optimization for Firefox. Since Spidermonkey does not fully parse the
35
+ // contents of a function until the first time it's called, and since it will
36
+ // never actually need to be called, this allows the polyfill to be included
37
+ // in Firefox nearly for free.
38
+ const wrapAPIs = extensionAPIs => {
39
+ // NOTE: apiMetadata is associated to the content of the api-metadata.json file
40
+ // at build time by replacing the following "include" with the content of the
41
+ // JSON file.
42
+ const apiMetadata = {
43
+ "alarms": {
44
+ "clear": {
45
+ "minArgs": 0,
46
+ "maxArgs": 1
47
+ },
48
+ "clearAll": {
49
+ "minArgs": 0,
50
+ "maxArgs": 0
51
+ },
52
+ "get": {
53
+ "minArgs": 0,
54
+ "maxArgs": 1
55
+ },
56
+ "getAll": {
57
+ "minArgs": 0,
58
+ "maxArgs": 0
59
+ }
60
+ },
61
+ "bookmarks": {
62
+ "create": {
63
+ "minArgs": 1,
64
+ "maxArgs": 1
65
+ },
66
+ "get": {
67
+ "minArgs": 1,
68
+ "maxArgs": 1
69
+ },
70
+ "getChildren": {
71
+ "minArgs": 1,
72
+ "maxArgs": 1
73
+ },
74
+ "getRecent": {
75
+ "minArgs": 1,
76
+ "maxArgs": 1
77
+ },
78
+ "getSubTree": {
79
+ "minArgs": 1,
80
+ "maxArgs": 1
81
+ },
82
+ "getTree": {
83
+ "minArgs": 0,
84
+ "maxArgs": 0
85
+ },
86
+ "move": {
87
+ "minArgs": 2,
88
+ "maxArgs": 2
89
+ },
90
+ "remove": {
91
+ "minArgs": 1,
92
+ "maxArgs": 1
93
+ },
94
+ "removeTree": {
95
+ "minArgs": 1,
96
+ "maxArgs": 1
97
+ },
98
+ "search": {
99
+ "minArgs": 1,
100
+ "maxArgs": 1
101
+ },
102
+ "update": {
103
+ "minArgs": 2,
104
+ "maxArgs": 2
105
+ }
106
+ },
107
+ "browserAction": {
108
+ "disable": {
109
+ "minArgs": 0,
110
+ "maxArgs": 1,
111
+ "fallbackToNoCallback": true
112
+ },
113
+ "enable": {
114
+ "minArgs": 0,
115
+ "maxArgs": 1,
116
+ "fallbackToNoCallback": true
117
+ },
118
+ "getBadgeBackgroundColor": {
119
+ "minArgs": 1,
120
+ "maxArgs": 1
121
+ },
122
+ "getBadgeText": {
123
+ "minArgs": 1,
124
+ "maxArgs": 1
125
+ },
126
+ "getPopup": {
127
+ "minArgs": 1,
128
+ "maxArgs": 1
129
+ },
130
+ "getTitle": {
131
+ "minArgs": 1,
132
+ "maxArgs": 1
133
+ },
134
+ "openPopup": {
135
+ "minArgs": 0,
136
+ "maxArgs": 0
137
+ },
138
+ "setBadgeBackgroundColor": {
139
+ "minArgs": 1,
140
+ "maxArgs": 1,
141
+ "fallbackToNoCallback": true
142
+ },
143
+ "setBadgeText": {
144
+ "minArgs": 1,
145
+ "maxArgs": 1,
146
+ "fallbackToNoCallback": true
147
+ },
148
+ "setIcon": {
149
+ "minArgs": 1,
150
+ "maxArgs": 1
151
+ },
152
+ "setPopup": {
153
+ "minArgs": 1,
154
+ "maxArgs": 1,
155
+ "fallbackToNoCallback": true
156
+ },
157
+ "setTitle": {
158
+ "minArgs": 1,
159
+ "maxArgs": 1,
160
+ "fallbackToNoCallback": true
161
+ }
162
+ },
163
+ "browsingData": {
164
+ "remove": {
165
+ "minArgs": 2,
166
+ "maxArgs": 2
167
+ },
168
+ "removeCache": {
169
+ "minArgs": 1,
170
+ "maxArgs": 1
171
+ },
172
+ "removeCookies": {
173
+ "minArgs": 1,
174
+ "maxArgs": 1
175
+ },
176
+ "removeDownloads": {
177
+ "minArgs": 1,
178
+ "maxArgs": 1
179
+ },
180
+ "removeFormData": {
181
+ "minArgs": 1,
182
+ "maxArgs": 1
183
+ },
184
+ "removeHistory": {
185
+ "minArgs": 1,
186
+ "maxArgs": 1
187
+ },
188
+ "removeLocalStorage": {
189
+ "minArgs": 1,
190
+ "maxArgs": 1
191
+ },
192
+ "removePasswords": {
193
+ "minArgs": 1,
194
+ "maxArgs": 1
195
+ },
196
+ "removePluginData": {
197
+ "minArgs": 1,
198
+ "maxArgs": 1
199
+ },
200
+ "settings": {
201
+ "minArgs": 0,
202
+ "maxArgs": 0
203
+ }
204
+ },
205
+ "commands": {
206
+ "getAll": {
207
+ "minArgs": 0,
208
+ "maxArgs": 0
209
+ }
210
+ },
211
+ "contextMenus": {
212
+ "remove": {
213
+ "minArgs": 1,
214
+ "maxArgs": 1
215
+ },
216
+ "removeAll": {
217
+ "minArgs": 0,
218
+ "maxArgs": 0
219
+ },
220
+ "update": {
221
+ "minArgs": 2,
222
+ "maxArgs": 2
223
+ }
224
+ },
225
+ "cookies": {
226
+ "get": {
227
+ "minArgs": 1,
228
+ "maxArgs": 1
229
+ },
230
+ "getAll": {
231
+ "minArgs": 1,
232
+ "maxArgs": 1
233
+ },
234
+ "getAllCookieStores": {
235
+ "minArgs": 0,
236
+ "maxArgs": 0
237
+ },
238
+ "remove": {
239
+ "minArgs": 1,
240
+ "maxArgs": 1
241
+ },
242
+ "set": {
243
+ "minArgs": 1,
244
+ "maxArgs": 1
245
+ }
246
+ },
247
+ "devtools": {
248
+ "inspectedWindow": {
249
+ "eval": {
250
+ "minArgs": 1,
251
+ "maxArgs": 2,
252
+ "singleCallbackArg": false
253
+ }
254
+ },
255
+ "panels": {
256
+ "create": {
257
+ "minArgs": 3,
258
+ "maxArgs": 3,
259
+ "singleCallbackArg": true
260
+ },
261
+ "elements": {
262
+ "createSidebarPane": {
263
+ "minArgs": 1,
264
+ "maxArgs": 1
265
+ }
266
+ }
267
+ }
268
+ },
269
+ "downloads": {
270
+ "cancel": {
271
+ "minArgs": 1,
272
+ "maxArgs": 1
273
+ },
274
+ "download": {
275
+ "minArgs": 1,
276
+ "maxArgs": 1
277
+ },
278
+ "erase": {
279
+ "minArgs": 1,
280
+ "maxArgs": 1
281
+ },
282
+ "getFileIcon": {
283
+ "minArgs": 1,
284
+ "maxArgs": 2
285
+ },
286
+ "open": {
287
+ "minArgs": 1,
288
+ "maxArgs": 1,
289
+ "fallbackToNoCallback": true
290
+ },
291
+ "pause": {
292
+ "minArgs": 1,
293
+ "maxArgs": 1
294
+ },
295
+ "removeFile": {
296
+ "minArgs": 1,
297
+ "maxArgs": 1
298
+ },
299
+ "resume": {
300
+ "minArgs": 1,
301
+ "maxArgs": 1
302
+ },
303
+ "search": {
304
+ "minArgs": 1,
305
+ "maxArgs": 1
306
+ },
307
+ "show": {
308
+ "minArgs": 1,
309
+ "maxArgs": 1,
310
+ "fallbackToNoCallback": true
311
+ }
312
+ },
313
+ "extension": {
314
+ "isAllowedFileSchemeAccess": {
315
+ "minArgs": 0,
316
+ "maxArgs": 0
317
+ },
318
+ "isAllowedIncognitoAccess": {
319
+ "minArgs": 0,
320
+ "maxArgs": 0
321
+ }
322
+ },
323
+ "history": {
324
+ "addUrl": {
325
+ "minArgs": 1,
326
+ "maxArgs": 1
327
+ },
328
+ "deleteAll": {
329
+ "minArgs": 0,
330
+ "maxArgs": 0
331
+ },
332
+ "deleteRange": {
333
+ "minArgs": 1,
334
+ "maxArgs": 1
335
+ },
336
+ "deleteUrl": {
337
+ "minArgs": 1,
338
+ "maxArgs": 1
339
+ },
340
+ "getVisits": {
341
+ "minArgs": 1,
342
+ "maxArgs": 1
343
+ },
344
+ "search": {
345
+ "minArgs": 1,
346
+ "maxArgs": 1
347
+ }
348
+ },
349
+ "i18n": {
350
+ "detectLanguage": {
351
+ "minArgs": 1,
352
+ "maxArgs": 1
353
+ },
354
+ "getAcceptLanguages": {
355
+ "minArgs": 0,
356
+ "maxArgs": 0
357
+ }
358
+ },
359
+ "identity": {
360
+ "launchWebAuthFlow": {
361
+ "minArgs": 1,
362
+ "maxArgs": 1
363
+ }
364
+ },
365
+ "idle": {
366
+ "queryState": {
367
+ "minArgs": 1,
368
+ "maxArgs": 1
369
+ }
370
+ },
371
+ "management": {
372
+ "get": {
373
+ "minArgs": 1,
374
+ "maxArgs": 1
375
+ },
376
+ "getAll": {
377
+ "minArgs": 0,
378
+ "maxArgs": 0
379
+ },
380
+ "getSelf": {
381
+ "minArgs": 0,
382
+ "maxArgs": 0
383
+ },
384
+ "setEnabled": {
385
+ "minArgs": 2,
386
+ "maxArgs": 2
387
+ },
388
+ "uninstallSelf": {
389
+ "minArgs": 0,
390
+ "maxArgs": 1
391
+ }
392
+ },
393
+ "notifications": {
394
+ "clear": {
395
+ "minArgs": 1,
396
+ "maxArgs": 1
397
+ },
398
+ "create": {
399
+ "minArgs": 1,
400
+ "maxArgs": 2
401
+ },
402
+ "getAll": {
403
+ "minArgs": 0,
404
+ "maxArgs": 0
405
+ },
406
+ "getPermissionLevel": {
407
+ "minArgs": 0,
408
+ "maxArgs": 0
409
+ },
410
+ "update": {
411
+ "minArgs": 2,
412
+ "maxArgs": 2
413
+ }
414
+ },
415
+ "pageAction": {
416
+ "getPopup": {
417
+ "minArgs": 1,
418
+ "maxArgs": 1
419
+ },
420
+ "getTitle": {
421
+ "minArgs": 1,
422
+ "maxArgs": 1
423
+ },
424
+ "hide": {
425
+ "minArgs": 1,
426
+ "maxArgs": 1,
427
+ "fallbackToNoCallback": true
428
+ },
429
+ "setIcon": {
430
+ "minArgs": 1,
431
+ "maxArgs": 1
432
+ },
433
+ "setPopup": {
434
+ "minArgs": 1,
435
+ "maxArgs": 1,
436
+ "fallbackToNoCallback": true
437
+ },
438
+ "setTitle": {
439
+ "minArgs": 1,
440
+ "maxArgs": 1,
441
+ "fallbackToNoCallback": true
442
+ },
443
+ "show": {
444
+ "minArgs": 1,
445
+ "maxArgs": 1,
446
+ "fallbackToNoCallback": true
447
+ }
448
+ },
449
+ "permissions": {
450
+ "contains": {
451
+ "minArgs": 1,
452
+ "maxArgs": 1
453
+ },
454
+ "getAll": {
455
+ "minArgs": 0,
456
+ "maxArgs": 0
457
+ },
458
+ "remove": {
459
+ "minArgs": 1,
460
+ "maxArgs": 1
461
+ },
462
+ "request": {
463
+ "minArgs": 1,
464
+ "maxArgs": 1
465
+ }
466
+ },
467
+ "runtime": {
468
+ "getBackgroundPage": {
469
+ "minArgs": 0,
470
+ "maxArgs": 0
471
+ },
472
+ "getPlatformInfo": {
473
+ "minArgs": 0,
474
+ "maxArgs": 0
475
+ },
476
+ "openOptionsPage": {
477
+ "minArgs": 0,
478
+ "maxArgs": 0
479
+ },
480
+ "requestUpdateCheck": {
481
+ "minArgs": 0,
482
+ "maxArgs": 0
483
+ },
484
+ "sendMessage": {
485
+ "minArgs": 1,
486
+ "maxArgs": 3
487
+ },
488
+ "sendNativeMessage": {
489
+ "minArgs": 2,
490
+ "maxArgs": 2
491
+ },
492
+ "setUninstallURL": {
493
+ "minArgs": 1,
494
+ "maxArgs": 1
495
+ }
496
+ },
497
+ "sessions": {
498
+ "getDevices": {
499
+ "minArgs": 0,
500
+ "maxArgs": 1
501
+ },
502
+ "getRecentlyClosed": {
503
+ "minArgs": 0,
504
+ "maxArgs": 1
505
+ },
506
+ "restore": {
507
+ "minArgs": 0,
508
+ "maxArgs": 1
509
+ }
510
+ },
511
+ "storage": {
512
+ "local": {
513
+ "clear": {
514
+ "minArgs": 0,
515
+ "maxArgs": 0
516
+ },
517
+ "get": {
518
+ "minArgs": 0,
519
+ "maxArgs": 1
520
+ },
521
+ "getBytesInUse": {
522
+ "minArgs": 0,
523
+ "maxArgs": 1
524
+ },
525
+ "remove": {
526
+ "minArgs": 1,
527
+ "maxArgs": 1
528
+ },
529
+ "set": {
530
+ "minArgs": 1,
531
+ "maxArgs": 1
532
+ }
533
+ },
534
+ "managed": {
535
+ "get": {
536
+ "minArgs": 0,
537
+ "maxArgs": 1
538
+ },
539
+ "getBytesInUse": {
540
+ "minArgs": 0,
541
+ "maxArgs": 1
542
+ }
543
+ },
544
+ "sync": {
545
+ "clear": {
546
+ "minArgs": 0,
547
+ "maxArgs": 0
548
+ },
549
+ "get": {
550
+ "minArgs": 0,
551
+ "maxArgs": 1
552
+ },
553
+ "getBytesInUse": {
554
+ "minArgs": 0,
555
+ "maxArgs": 1
556
+ },
557
+ "remove": {
558
+ "minArgs": 1,
559
+ "maxArgs": 1
560
+ },
561
+ "set": {
562
+ "minArgs": 1,
563
+ "maxArgs": 1
564
+ }
565
+ }
566
+ },
567
+ "tabs": {
568
+ "captureVisibleTab": {
569
+ "minArgs": 0,
570
+ "maxArgs": 2
571
+ },
572
+ "create": {
573
+ "minArgs": 1,
574
+ "maxArgs": 1
575
+ },
576
+ "detectLanguage": {
577
+ "minArgs": 0,
578
+ "maxArgs": 1
579
+ },
580
+ "discard": {
581
+ "minArgs": 0,
582
+ "maxArgs": 1
583
+ },
584
+ "duplicate": {
585
+ "minArgs": 1,
586
+ "maxArgs": 1
587
+ },
588
+ "executeScript": {
589
+ "minArgs": 1,
590
+ "maxArgs": 2
591
+ },
592
+ "get": {
593
+ "minArgs": 1,
594
+ "maxArgs": 1
595
+ },
596
+ "getCurrent": {
597
+ "minArgs": 0,
598
+ "maxArgs": 0
599
+ },
600
+ "getZoom": {
601
+ "minArgs": 0,
602
+ "maxArgs": 1
603
+ },
604
+ "getZoomSettings": {
605
+ "minArgs": 0,
606
+ "maxArgs": 1
607
+ },
608
+ "goBack": {
609
+ "minArgs": 0,
610
+ "maxArgs": 1
611
+ },
612
+ "goForward": {
613
+ "minArgs": 0,
614
+ "maxArgs": 1
615
+ },
616
+ "highlight": {
617
+ "minArgs": 1,
618
+ "maxArgs": 1
619
+ },
620
+ "insertCSS": {
621
+ "minArgs": 1,
622
+ "maxArgs": 2
623
+ },
624
+ "move": {
625
+ "minArgs": 2,
626
+ "maxArgs": 2
627
+ },
628
+ "query": {
629
+ "minArgs": 1,
630
+ "maxArgs": 1
631
+ },
632
+ "reload": {
633
+ "minArgs": 0,
634
+ "maxArgs": 2
635
+ },
636
+ "remove": {
637
+ "minArgs": 1,
638
+ "maxArgs": 1
639
+ },
640
+ "removeCSS": {
641
+ "minArgs": 1,
642
+ "maxArgs": 2
643
+ },
644
+ "sendMessage": {
645
+ "minArgs": 2,
646
+ "maxArgs": 3
647
+ },
648
+ "setZoom": {
649
+ "minArgs": 1,
650
+ "maxArgs": 2
651
+ },
652
+ "setZoomSettings": {
653
+ "minArgs": 1,
654
+ "maxArgs": 2
655
+ },
656
+ "update": {
657
+ "minArgs": 1,
658
+ "maxArgs": 2
659
+ }
660
+ },
661
+ "topSites": {
662
+ "get": {
663
+ "minArgs": 0,
664
+ "maxArgs": 0
665
+ }
666
+ },
667
+ "webNavigation": {
668
+ "getAllFrames": {
669
+ "minArgs": 1,
670
+ "maxArgs": 1
671
+ },
672
+ "getFrame": {
673
+ "minArgs": 1,
674
+ "maxArgs": 1
675
+ }
676
+ },
677
+ "webRequest": {
678
+ "handlerBehaviorChanged": {
679
+ "minArgs": 0,
680
+ "maxArgs": 0
681
+ }
682
+ },
683
+ "windows": {
684
+ "create": {
685
+ "minArgs": 0,
686
+ "maxArgs": 1
687
+ },
688
+ "get": {
689
+ "minArgs": 1,
690
+ "maxArgs": 2
691
+ },
692
+ "getAll": {
693
+ "minArgs": 0,
694
+ "maxArgs": 1
695
+ },
696
+ "getCurrent": {
697
+ "minArgs": 0,
698
+ "maxArgs": 1
699
+ },
700
+ "getLastFocused": {
701
+ "minArgs": 0,
702
+ "maxArgs": 1
703
+ },
704
+ "remove": {
705
+ "minArgs": 1,
706
+ "maxArgs": 1
707
+ },
708
+ "update": {
709
+ "minArgs": 2,
710
+ "maxArgs": 2
711
+ }
712
+ }
713
+ };
714
+ if (Object.keys(apiMetadata).length === 0) {
715
+ throw new Error("api-metadata.json has not been included in browser-polyfill");
716
+ }
717
+
718
+ /**
719
+ * A WeakMap subclass which creates and stores a value for any key which does
720
+ * not exist when accessed, but behaves exactly as an ordinary WeakMap
721
+ * otherwise.
722
+ *
723
+ * @param {function} createItem
724
+ * A function which will be called in order to create the value for any
725
+ * key which does not exist, the first time it is accessed. The
726
+ * function receives, as its only argument, the key being created.
727
+ */
728
+ class DefaultWeakMap extends WeakMap {
729
+ constructor(createItem, items = undefined) {
730
+ super(items);
731
+ this.createItem = createItem;
732
+ }
733
+ get(key) {
734
+ if (!this.has(key)) {
735
+ this.set(key, this.createItem(key));
736
+ }
737
+ return super.get(key);
738
+ }
739
+ }
740
+
741
+ /**
742
+ * Returns true if the given object is an object with a `then` method, and can
743
+ * therefore be assumed to behave as a Promise.
744
+ *
745
+ * @param {*} value The value to test.
746
+ * @returns {boolean} True if the value is thenable.
747
+ */
748
+ const isThenable = value => {
749
+ return value && typeof value === "object" && typeof value.then === "function";
750
+ };
751
+
752
+ /**
753
+ * Creates and returns a function which, when called, will resolve or reject
754
+ * the given promise based on how it is called:
755
+ *
756
+ * - If, when called, `chrome.runtime.lastError` contains a non-null object,
757
+ * the promise is rejected with that value.
758
+ * - If the function is called with exactly one argument, the promise is
759
+ * resolved to that value.
760
+ * - Otherwise, the promise is resolved to an array containing all of the
761
+ * function's arguments.
762
+ *
763
+ * @param {object} promise
764
+ * An object containing the resolution and rejection functions of a
765
+ * promise.
766
+ * @param {function} promise.resolve
767
+ * The promise's resolution function.
768
+ * @param {function} promise.reject
769
+ * The promise's rejection function.
770
+ * @param {object} metadata
771
+ * Metadata about the wrapped method which has created the callback.
772
+ * @param {boolean} metadata.singleCallbackArg
773
+ * Whether or not the promise is resolved with only the first
774
+ * argument of the callback, alternatively an array of all the
775
+ * callback arguments is resolved. By default, if the callback
776
+ * function is invoked with only a single argument, that will be
777
+ * resolved to the promise, while all arguments will be resolved as
778
+ * an array if multiple are given.
779
+ *
780
+ * @returns {function}
781
+ * The generated callback function.
782
+ */
783
+ const makeCallback = (promise, metadata) => {
784
+ return (...callbackArgs) => {
785
+ if (extensionAPIs.runtime.lastError) {
786
+ promise.reject(new Error(extensionAPIs.runtime.lastError.message));
787
+ } else if (metadata.singleCallbackArg || callbackArgs.length <= 1 && metadata.singleCallbackArg !== false) {
788
+ promise.resolve(callbackArgs[0]);
789
+ } else {
790
+ promise.resolve(callbackArgs);
791
+ }
792
+ };
793
+ };
794
+ const pluralizeArguments = numArgs => numArgs == 1 ? "argument" : "arguments";
795
+
796
+ /**
797
+ * Creates a wrapper function for a method with the given name and metadata.
798
+ *
799
+ * @param {string} name
800
+ * The name of the method which is being wrapped.
801
+ * @param {object} metadata
802
+ * Metadata about the method being wrapped.
803
+ * @param {integer} metadata.minArgs
804
+ * The minimum number of arguments which must be passed to the
805
+ * function. If called with fewer than this number of arguments, the
806
+ * wrapper will raise an exception.
807
+ * @param {integer} metadata.maxArgs
808
+ * The maximum number of arguments which may be passed to the
809
+ * function. If called with more than this number of arguments, the
810
+ * wrapper will raise an exception.
811
+ * @param {boolean} metadata.singleCallbackArg
812
+ * Whether or not the promise is resolved with only the first
813
+ * argument of the callback, alternatively an array of all the
814
+ * callback arguments is resolved. By default, if the callback
815
+ * function is invoked with only a single argument, that will be
816
+ * resolved to the promise, while all arguments will be resolved as
817
+ * an array if multiple are given.
818
+ *
819
+ * @returns {function(object, ...*)}
820
+ * The generated wrapper function.
821
+ */
822
+ const wrapAsyncFunction = (name, metadata) => {
823
+ return function asyncFunctionWrapper(target, ...args) {
824
+ if (args.length < metadata.minArgs) {
825
+ throw new Error(`Expected at least ${metadata.minArgs} ${pluralizeArguments(metadata.minArgs)} for ${name}(), got ${args.length}`);
826
+ }
827
+ if (args.length > metadata.maxArgs) {
828
+ throw new Error(`Expected at most ${metadata.maxArgs} ${pluralizeArguments(metadata.maxArgs)} for ${name}(), got ${args.length}`);
829
+ }
830
+ return new Promise((resolve, reject) => {
831
+ if (metadata.fallbackToNoCallback) {
832
+ // This API method has currently no callback on Chrome, but it return a promise on Firefox,
833
+ // and so the polyfill will try to call it with a callback first, and it will fallback
834
+ // to not passing the callback if the first call fails.
835
+ try {
836
+ target[name](...args, makeCallback({
837
+ resolve,
838
+ reject
839
+ }, metadata));
840
+ } catch (cbError) {
841
+ console.warn(`${name} API method doesn't seem to support the callback parameter, ` + "falling back to call it without a callback: ", cbError);
842
+ target[name](...args);
843
+
844
+ // Update the API method metadata, so that the next API calls will not try to
845
+ // use the unsupported callback anymore.
846
+ metadata.fallbackToNoCallback = false;
847
+ metadata.noCallback = true;
848
+ resolve();
849
+ }
850
+ } else if (metadata.noCallback) {
851
+ target[name](...args);
852
+ resolve();
853
+ } else {
854
+ target[name](...args, makeCallback({
855
+ resolve,
856
+ reject
857
+ }, metadata));
858
+ }
859
+ });
860
+ };
861
+ };
862
+
863
+ /**
864
+ * Wraps an existing method of the target object, so that calls to it are
865
+ * intercepted by the given wrapper function. The wrapper function receives,
866
+ * as its first argument, the original `target` object, followed by each of
867
+ * the arguments passed to the original method.
868
+ *
869
+ * @param {object} target
870
+ * The original target object that the wrapped method belongs to.
871
+ * @param {function} method
872
+ * The method being wrapped. This is used as the target of the Proxy
873
+ * object which is created to wrap the method.
874
+ * @param {function} wrapper
875
+ * The wrapper function which is called in place of a direct invocation
876
+ * of the wrapped method.
877
+ *
878
+ * @returns {Proxy<function>}
879
+ * A Proxy object for the given method, which invokes the given wrapper
880
+ * method in its place.
881
+ */
882
+ const wrapMethod = (target, method, wrapper) => {
883
+ return new Proxy(method, {
884
+ apply(targetMethod, thisObj, args) {
885
+ return wrapper.call(thisObj, target, ...args);
886
+ }
887
+ });
888
+ };
889
+ let hasOwnProperty = Function.call.bind(Object.prototype.hasOwnProperty);
890
+
891
+ /**
892
+ * Wraps an object in a Proxy which intercepts and wraps certain methods
893
+ * based on the given `wrappers` and `metadata` objects.
894
+ *
895
+ * @param {object} target
896
+ * The target object to wrap.
897
+ *
898
+ * @param {object} [wrappers = {}]
899
+ * An object tree containing wrapper functions for special cases. Any
900
+ * function present in this object tree is called in place of the
901
+ * method in the same location in the `target` object tree. These
902
+ * wrapper methods are invoked as described in {@see wrapMethod}.
903
+ *
904
+ * @param {object} [metadata = {}]
905
+ * An object tree containing metadata used to automatically generate
906
+ * Promise-based wrapper functions for asynchronous. Any function in
907
+ * the `target` object tree which has a corresponding metadata object
908
+ * in the same location in the `metadata` tree is replaced with an
909
+ * automatically-generated wrapper function, as described in
910
+ * {@see wrapAsyncFunction}
911
+ *
912
+ * @returns {Proxy<object>}
913
+ */
914
+ const wrapObject = (target, wrappers = {}, metadata = {}) => {
915
+ let cache = Object.create(null);
916
+ let handlers = {
917
+ has(proxyTarget, prop) {
918
+ return prop in target || prop in cache;
919
+ },
920
+ get(proxyTarget, prop, receiver) {
921
+ if (prop in cache) {
922
+ return cache[prop];
923
+ }
924
+ if (!(prop in target)) {
925
+ return undefined;
926
+ }
927
+ let value = target[prop];
928
+ if (typeof value === "function") {
929
+ // This is a method on the underlying object. Check if we need to do
930
+ // any wrapping.
931
+
932
+ if (typeof wrappers[prop] === "function") {
933
+ // We have a special-case wrapper for this method.
934
+ value = wrapMethod(target, target[prop], wrappers[prop]);
935
+ } else if (hasOwnProperty(metadata, prop)) {
936
+ // This is an async method that we have metadata for. Create a
937
+ // Promise wrapper for it.
938
+ let wrapper = wrapAsyncFunction(prop, metadata[prop]);
939
+ value = wrapMethod(target, target[prop], wrapper);
940
+ } else {
941
+ // This is a method that we don't know or care about. Return the
942
+ // original method, bound to the underlying object.
943
+ value = value.bind(target);
944
+ }
945
+ } else if (typeof value === "object" && value !== null && (hasOwnProperty(wrappers, prop) || hasOwnProperty(metadata, prop))) {
946
+ // This is an object that we need to do some wrapping for the children
947
+ // of. Create a sub-object wrapper for it with the appropriate child
948
+ // metadata.
949
+ value = wrapObject(value, wrappers[prop], metadata[prop]);
950
+ } else if (hasOwnProperty(metadata, "*")) {
951
+ // Wrap all properties in * namespace.
952
+ value = wrapObject(value, wrappers[prop], metadata["*"]);
953
+ } else {
954
+ // We don't need to do any wrapping for this property,
955
+ // so just forward all access to the underlying object.
956
+ Object.defineProperty(cache, prop, {
957
+ configurable: true,
958
+ enumerable: true,
959
+ get() {
960
+ return target[prop];
961
+ },
962
+ set(value) {
963
+ target[prop] = value;
964
+ }
965
+ });
966
+ return value;
967
+ }
968
+ cache[prop] = value;
969
+ return value;
970
+ },
971
+ set(proxyTarget, prop, value, receiver) {
972
+ if (prop in cache) {
973
+ cache[prop] = value;
974
+ } else {
975
+ target[prop] = value;
976
+ }
977
+ return true;
978
+ },
979
+ defineProperty(proxyTarget, prop, desc) {
980
+ return Reflect.defineProperty(cache, prop, desc);
981
+ },
982
+ deleteProperty(proxyTarget, prop) {
983
+ return Reflect.deleteProperty(cache, prop);
984
+ }
985
+ };
986
+
987
+ // Per contract of the Proxy API, the "get" proxy handler must return the
988
+ // original value of the target if that value is declared read-only and
989
+ // non-configurable. For this reason, we create an object with the
990
+ // prototype set to `target` instead of using `target` directly.
991
+ // Otherwise we cannot return a custom object for APIs that
992
+ // are declared read-only and non-configurable, such as `chrome.devtools`.
993
+ //
994
+ // The proxy handlers themselves will still use the original `target`
995
+ // instead of the `proxyTarget`, so that the methods and properties are
996
+ // dereferenced via the original targets.
997
+ let proxyTarget = Object.create(target);
998
+ return new Proxy(proxyTarget, handlers);
999
+ };
1000
+
1001
+ /**
1002
+ * Creates a set of wrapper functions for an event object, which handles
1003
+ * wrapping of listener functions that those messages are passed.
1004
+ *
1005
+ * A single wrapper is created for each listener function, and stored in a
1006
+ * map. Subsequent calls to `addListener`, `hasListener`, or `removeListener`
1007
+ * retrieve the original wrapper, so that attempts to remove a
1008
+ * previously-added listener work as expected.
1009
+ *
1010
+ * @param {DefaultWeakMap<function, function>} wrapperMap
1011
+ * A DefaultWeakMap object which will create the appropriate wrapper
1012
+ * for a given listener function when one does not exist, and retrieve
1013
+ * an existing one when it does.
1014
+ *
1015
+ * @returns {object}
1016
+ */
1017
+ const wrapEvent = wrapperMap => ({
1018
+ addListener(target, listener, ...args) {
1019
+ target.addListener(wrapperMap.get(listener), ...args);
1020
+ },
1021
+ hasListener(target, listener) {
1022
+ return target.hasListener(wrapperMap.get(listener));
1023
+ },
1024
+ removeListener(target, listener) {
1025
+ target.removeListener(wrapperMap.get(listener));
1026
+ }
1027
+ });
1028
+ const onRequestFinishedWrappers = new DefaultWeakMap(listener => {
1029
+ if (typeof listener !== "function") {
1030
+ return listener;
1031
+ }
1032
+
1033
+ /**
1034
+ * Wraps an onRequestFinished listener function so that it will return a
1035
+ * `getContent()` property which returns a `Promise` rather than using a
1036
+ * callback API.
1037
+ *
1038
+ * @param {object} req
1039
+ * The HAR entry object representing the network request.
1040
+ */
1041
+ return function onRequestFinished(req) {
1042
+ const wrappedReq = wrapObject(req, {} /* wrappers */, {
1043
+ getContent: {
1044
+ minArgs: 0,
1045
+ maxArgs: 0
1046
+ }
1047
+ });
1048
+ listener(wrappedReq);
1049
+ };
1050
+ });
1051
+ const onMessageWrappers = new DefaultWeakMap(listener => {
1052
+ if (typeof listener !== "function") {
1053
+ return listener;
1054
+ }
1055
+
1056
+ /**
1057
+ * Wraps a message listener function so that it may send responses based on
1058
+ * its return value, rather than by returning a sentinel value and calling a
1059
+ * callback. If the listener function returns a Promise, the response is
1060
+ * sent when the promise either resolves or rejects.
1061
+ *
1062
+ * @param {*} message
1063
+ * The message sent by the other end of the channel.
1064
+ * @param {object} sender
1065
+ * Details about the sender of the message.
1066
+ * @param {function(*)} sendResponse
1067
+ * A callback which, when called with an arbitrary argument, sends
1068
+ * that value as a response.
1069
+ * @returns {boolean}
1070
+ * True if the wrapped listener returned a Promise, which will later
1071
+ * yield a response. False otherwise.
1072
+ */
1073
+ return function onMessage(message, sender, sendResponse) {
1074
+ let didCallSendResponse = false;
1075
+ let wrappedSendResponse;
1076
+ let sendResponsePromise = new Promise(resolve => {
1077
+ wrappedSendResponse = function (response) {
1078
+ didCallSendResponse = true;
1079
+ resolve(response);
1080
+ };
1081
+ });
1082
+ let result;
1083
+ try {
1084
+ result = listener(message, sender, wrappedSendResponse);
1085
+ } catch (err) {
1086
+ result = Promise.reject(err);
1087
+ }
1088
+ const isResultThenable = result !== true && isThenable(result);
1089
+
1090
+ // If the listener didn't returned true or a Promise, or called
1091
+ // wrappedSendResponse synchronously, we can exit earlier
1092
+ // because there will be no response sent from this listener.
1093
+ if (result !== true && !isResultThenable && !didCallSendResponse) {
1094
+ return false;
1095
+ }
1096
+
1097
+ // A small helper to send the message if the promise resolves
1098
+ // and an error if the promise rejects (a wrapped sendMessage has
1099
+ // to translate the message into a resolved promise or a rejected
1100
+ // promise).
1101
+ const sendPromisedResult = promise => {
1102
+ promise.then(msg => {
1103
+ // send the message value.
1104
+ sendResponse(msg);
1105
+ }, error => {
1106
+ // Send a JSON representation of the error if the rejected value
1107
+ // is an instance of error, or the object itself otherwise.
1108
+ let message;
1109
+ if (error && (error instanceof Error || typeof error.message === "string")) {
1110
+ message = error.message;
1111
+ } else {
1112
+ message = "An unexpected error occurred";
1113
+ }
1114
+ sendResponse({
1115
+ __mozWebExtensionPolyfillReject__: true,
1116
+ message
1117
+ });
1118
+ }).catch(err => {
1119
+ // Print an error on the console if unable to send the response.
1120
+ console.error("Failed to send onMessage rejected reply", err);
1121
+ });
1122
+ };
1123
+
1124
+ // If the listener returned a Promise, send the resolved value as a
1125
+ // result, otherwise wait the promise related to the wrappedSendResponse
1126
+ // callback to resolve and send it as a response.
1127
+ if (isResultThenable) {
1128
+ sendPromisedResult(result);
1129
+ } else {
1130
+ sendPromisedResult(sendResponsePromise);
1131
+ }
1132
+
1133
+ // Let Chrome know that the listener is replying.
1134
+ return true;
1135
+ };
1136
+ });
1137
+ const wrappedSendMessageCallback = ({
1138
+ reject,
1139
+ resolve
1140
+ }, reply) => {
1141
+ if (extensionAPIs.runtime.lastError) {
1142
+ // Detect when none of the listeners replied to the sendMessage call and resolve
1143
+ // the promise to undefined as in Firefox.
1144
+ // See https://github.com/mozilla/webextension-polyfill/issues/130
1145
+ if (extensionAPIs.runtime.lastError.message === CHROME_SEND_MESSAGE_CALLBACK_NO_RESPONSE_MESSAGE) {
1146
+ resolve();
1147
+ } else {
1148
+ reject(new Error(extensionAPIs.runtime.lastError.message));
1149
+ }
1150
+ } else if (reply && reply.__mozWebExtensionPolyfillReject__) {
1151
+ // Convert back the JSON representation of the error into
1152
+ // an Error instance.
1153
+ reject(new Error(reply.message));
1154
+ } else {
1155
+ resolve(reply);
1156
+ }
1157
+ };
1158
+ const wrappedSendMessage = (name, metadata, apiNamespaceObj, ...args) => {
1159
+ if (args.length < metadata.minArgs) {
1160
+ throw new Error(`Expected at least ${metadata.minArgs} ${pluralizeArguments(metadata.minArgs)} for ${name}(), got ${args.length}`);
1161
+ }
1162
+ if (args.length > metadata.maxArgs) {
1163
+ throw new Error(`Expected at most ${metadata.maxArgs} ${pluralizeArguments(metadata.maxArgs)} for ${name}(), got ${args.length}`);
1164
+ }
1165
+ return new Promise((resolve, reject) => {
1166
+ const wrappedCb = wrappedSendMessageCallback.bind(null, {
1167
+ resolve,
1168
+ reject
1169
+ });
1170
+ args.push(wrappedCb);
1171
+ apiNamespaceObj.sendMessage(...args);
1172
+ });
1173
+ };
1174
+ const staticWrappers = {
1175
+ devtools: {
1176
+ network: {
1177
+ onRequestFinished: wrapEvent(onRequestFinishedWrappers)
1178
+ }
1179
+ },
1180
+ runtime: {
1181
+ onMessage: wrapEvent(onMessageWrappers),
1182
+ onMessageExternal: wrapEvent(onMessageWrappers),
1183
+ sendMessage: wrappedSendMessage.bind(null, "sendMessage", {
1184
+ minArgs: 1,
1185
+ maxArgs: 3
1186
+ })
1187
+ },
1188
+ tabs: {
1189
+ sendMessage: wrappedSendMessage.bind(null, "sendMessage", {
1190
+ minArgs: 2,
1191
+ maxArgs: 3
1192
+ })
1193
+ }
1194
+ };
1195
+ const settingMetadata = {
1196
+ clear: {
1197
+ minArgs: 1,
1198
+ maxArgs: 1
1199
+ },
1200
+ get: {
1201
+ minArgs: 1,
1202
+ maxArgs: 1
1203
+ },
1204
+ set: {
1205
+ minArgs: 1,
1206
+ maxArgs: 1
1207
+ }
1208
+ };
1209
+ apiMetadata.privacy = {
1210
+ network: {
1211
+ "*": settingMetadata
1212
+ },
1213
+ services: {
1214
+ "*": settingMetadata
1215
+ },
1216
+ websites: {
1217
+ "*": settingMetadata
1218
+ }
1219
+ };
1220
+ return wrapObject(extensionAPIs, staticWrappers, apiMetadata);
1221
+ };
1222
+
1223
+ // The build process adds a UMD wrapper around this file, which makes the
1224
+ // `module` variable available.
1225
+ module.exports = wrapAPIs(chrome);
1226
+ } else {
1227
+ module.exports = globalThis.browser;
1228
+ }
1229
+ });
1230
+ //# sourceMappingURL=browser-polyfill.js.map
1231
+
1232
+
1233
+ /***/ }
1234
+
1235
+ /******/ });
1236
+ /************************************************************************/
1237
+ /******/ // The module cache
1238
+ /******/ const __webpack_module_cache__ = {};
1239
+ /******/
1240
+ /******/ // The require function
1241
+ /******/ function __webpack_require__(moduleId) {
1242
+ /******/ // Check if module is in cache
1243
+ /******/ const cachedModule = __webpack_module_cache__[moduleId];
1244
+ /******/ if (cachedModule !== undefined) {
1245
+ /******/ return cachedModule.exports;
1246
+ /******/ }
1247
+ /******/ // Create a new module (and put it into the cache)
1248
+ /******/ const module = __webpack_module_cache__[moduleId] = {
1249
+ /******/ // no module.id needed
1250
+ /******/ // no module.loaded needed
1251
+ /******/ exports: {}
1252
+ /******/ };
1253
+ /******/
1254
+ /******/ // Execute the module function
1255
+ /******/ if (!(moduleId in __webpack_modules__)) {
1256
+ /******/ delete __webpack_module_cache__[moduleId];
1257
+ /******/ const e = new Error("Cannot find module '" + moduleId + "'");
1258
+ /******/ e.code = 'MODULE_NOT_FOUND';
1259
+ /******/ throw e;
1260
+ /******/ }
1261
+ /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
1262
+ /******/
1263
+ /******/ // Return the exports of the module
1264
+ /******/ return module.exports;
1265
+ /******/ }
1266
+ /******/
1267
+ /************************************************************************/
1268
+ /******/ /* webpack/runtime/define property getters */
1269
+ /******/ (() => {
1270
+ /******/ // define getter/value functions for harmony exports
1271
+ /******/ __webpack_require__.d = (exports, definition) => {
1272
+ /******/ if(Array.isArray(definition)) {
1273
+ /******/ var i = 0;
1274
+ /******/ while(i < definition.length) {
1275
+ /******/ var key = definition[i++];
1276
+ /******/ var binding = definition[i++];
1277
+ /******/ if(!__webpack_require__.o(exports, key)) {
1278
+ /******/ if(binding === 0) {
1279
+ /******/ Object.defineProperty(exports, key, { enumerable: true, value: definition[i++] });
1280
+ /******/ } else {
1281
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: binding });
1282
+ /******/ }
1283
+ /******/ } else if(binding === 0) { i++; }
1284
+ /******/ }
1285
+ /******/ } else {
1286
+ /******/ for(var key in definition) {
1287
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
1288
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
1289
+ /******/ }
1290
+ /******/ }
1291
+ /******/ }
1292
+ /******/ };
1293
+ /******/ })();
1294
+ /******/
1295
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
1296
+ /******/ (() => {
1297
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
1298
+ /******/ })();
1299
+ /******/
1300
+ /******/ /* webpack/runtime/make namespace object */
1301
+ /******/ (() => {
1302
+ /******/ // define __esModule on exports
1303
+ /******/ __webpack_require__.r = (exports) => {
1304
+ /******/ if(Symbol.toStringTag) {
1305
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1306
+ /******/ }
1307
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
1308
+ /******/ };
1309
+ /******/ })();
1310
+ /******/
1311
+ /******/ /* webpack/runtime/set anonymous default export name */
1312
+ /******/ (() => {
1313
+ /******/ // set .name for anonymous default exports per ES spec
1314
+ /******/ __webpack_require__.dn = (x) => {
1315
+ /******/ (Object.getOwnPropertyDescriptor(x, "name") || {}).writable || Object.defineProperty(x, "name", { value: "default", configurable: true });
1316
+ /******/ };
1317
+ /******/ })();
1318
+ /******/
1319
+ /************************************************************************/
1320
+ let __webpack_exports__ = {};
1321
+ // This entry needs to be wrapped in an IIFE because it needs to be in strict mode.
1322
+ (() => {
1323
+ "use strict";
1324
+ /*!**********************!*\
1325
+ !*** ./src/index.js ***!
1326
+ \**********************/
1327
+ __webpack_require__.r(__webpack_exports__);
1328
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1329
+ /* harmony export */ "default": () => (/* export default binding */ __WEBPACK_DEFAULT_EXPORT__)
1330
+ /* harmony export */ });
1331
+ __webpack_require__.dn(__WEBPACK_DEFAULT_EXPORT__);
1332
+ const browser = __webpack_require__(/*! webextension-polyfill */ "./node_modules/webextension-polyfill/dist/browser-polyfill.js");
1333
+
1334
+ const DESTROY_ACTION = `WEBEXTENSION_MESSAGES_DESTROY`;
1335
+ const RESULT_PROMISES = {};
1336
+ const ACTIONS = {};
1337
+
1338
+ browser.runtime.onMessage.addListener((message) => {
1339
+ if (message.action === DESTROY_ACTION) {
1340
+ destroy(message.payload);
1341
+ }
1342
+ });
1343
+
1344
+ /* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__(actions, messagesId = generateId()) {
1345
+ const messages = Object.fromEntries(
1346
+ Object.entries(actions).map(([action]) => [
1347
+ action,
1348
+ (payload) => sendMessageForResult(action, payload),
1349
+ ]),
1350
+ );
1351
+
1352
+ ACTIONS[messagesId] = (message) => onMessage(message, actions);
1353
+
1354
+ browser.runtime.onMessage.addListener(ACTIONS[messagesId]);
1355
+
1356
+ return {
1357
+ ...messages,
1358
+ destroy: () => destroy(messagesId, true),
1359
+ };
1360
+ }
1361
+
1362
+ async function onMessage(message, actions = {}) {
1363
+ if (RESULT_PROMISES[message.resultId]) {
1364
+ RESULT_PROMISES[message.resultId](message.payload);
1365
+ delete RESULT_PROMISES[message.resultId];
1366
+ return;
1367
+ }
1368
+
1369
+ if (actions[message.action]) {
1370
+ const payload = await actions[message.action](message.payload);
1371
+ sendMessage(message.action, payload, message.resultId);
1372
+ }
1373
+ }
1374
+
1375
+ function sendMessageForResult(action, payload) {
1376
+ const { resultId, promise } = createResultPromise();
1377
+ sendMessage(action, payload, resultId);
1378
+ return promise;
1379
+ }
1380
+
1381
+ function sendMessage(action, payload, resultId) {
1382
+ const message = { action, payload, resultId };
1383
+
1384
+ if (isBackgroundScript()) {
1385
+ getCurrentTab().then((tab) => browser.tabs.sendMessage(tab[0].id, message));
1386
+ } else {
1387
+ browser.runtime.sendMessage(message);
1388
+ }
1389
+ }
1390
+
1391
+ function createResultPromise() {
1392
+ const resultId = generateId();
1393
+
1394
+ return {
1395
+ promise: new Promise((res) => (RESULT_PROMISES[resultId] = res)),
1396
+ resultId,
1397
+ };
1398
+ }
1399
+
1400
+ function isBackgroundScript() {
1401
+ return (
1402
+ window.location.protocol === "chrome-extension:" ||
1403
+ window.location.protocol === "moz-extension:"
1404
+ );
1405
+ }
1406
+
1407
+ function generateId() {
1408
+ return `${Date.now()}-${Math.random()}`;
1409
+ }
1410
+
1411
+ function getCurrentTab() {
1412
+ return browser.tabs.query({ active: true, currentWindow: true });
1413
+ }
1414
+
1415
+ function destroy(messagesId, sendToReceiver) {
1416
+ browser.runtime.onMessage.removeListener(ACTIONS[messagesId]);
1417
+ delete ACTIONS[messagesId];
1418
+
1419
+ if (sendToReceiver) {
1420
+ sendMessage(DESTROY_ACTION, messagesId);
1421
+ }
1422
+ }
1423
+
1424
+ })();
1425
+
1426
+ /******/ })()
1427
+ ;