@wxt-dev/browser 0.2.8 → 0.3.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/README.md +1 -1
- package/package.json +2 -2
- package/src/gen/index.d.ts +90 -25
package/README.md
CHANGED
|
@@ -55,4 +55,4 @@ pnpm gen
|
|
|
55
55
|
|
|
56
56
|
With WXT, you must import the `browser` variable to use the extension APIs. The way `@types/chrome` is implemented forces you to define a global `chrome` variable. With WXT, this isn't acceptable, we don't want to pollute the global (type) scope or introduce conflicts with auto-imports.
|
|
57
57
|
|
|
58
|
-
Additionally, WXT overrides types to provide additional type safety for some APIs, like `browser.runtime.getURL` and `browser.i18n.getMessage`. With `@types/chrome`'s
|
|
58
|
+
Additionally, WXT overrides types to provide additional type safety for some APIs, like `browser.runtime.getURL` and `browser.i18n.getMessage`. With `@types/chrome`'s `declare namespace` definition, it's not possible to override the types for those functions.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxt-dev/browser",
|
|
3
3
|
"description": "Provides a cross-browser API for using extension APIs and types based on @types/chrome",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.mjs",
|
|
7
7
|
"types": "src/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"src"
|
|
26
26
|
],
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/chrome": "0.
|
|
28
|
+
"@types/chrome": "0.3.0",
|
|
29
29
|
"@types/node": "^22",
|
|
30
30
|
"typescript": "^6.0.3",
|
|
31
31
|
"vitest": "^4.1.10"
|
package/src/gen/index.d.ts
CHANGED
|
@@ -13,8 +13,20 @@ type SetPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
|
13
13
|
////////////////////
|
|
14
14
|
interface Window {
|
|
15
15
|
// chrome: typeof chrome;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Cross-browser alias of {@link chrome}.
|
|
19
|
+
* @since Chrome 148 (Chrome 152 for extensions declaring a `devtools_page` in manifest)
|
|
20
|
+
*/
|
|
21
|
+
browser: typeof chrome;
|
|
16
22
|
}
|
|
17
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Cross-browser alias of {@link chrome}.
|
|
26
|
+
* @since Chrome 148 (Chrome 152 for extensions declaring a `devtools_page` in manifest)
|
|
27
|
+
*/
|
|
28
|
+
declare var browser: typeof chrome;
|
|
29
|
+
|
|
18
30
|
export namespace Browser {
|
|
19
31
|
////////////////////
|
|
20
32
|
// Accessibility Features
|
|
@@ -527,7 +539,7 @@ export namespace Browser {
|
|
|
527
539
|
/** Device name */
|
|
528
540
|
deviceName: string;
|
|
529
541
|
/** Type of the device */
|
|
530
|
-
deviceType: DeviceType
|
|
542
|
+
deviceType: `${DeviceType}`;
|
|
531
543
|
/** The user-friendly name (e.g. "USB Microphone"). */
|
|
532
544
|
displayName: string;
|
|
533
545
|
/** The unique identifier of the audio device. */
|
|
@@ -539,14 +551,14 @@ export namespace Browser {
|
|
|
539
551
|
/** The stable/persisted device id string when available. */
|
|
540
552
|
stableDeviceId?: string;
|
|
541
553
|
/** Stream type associated with this device. */
|
|
542
|
-
streamType: StreamType
|
|
554
|
+
streamType: `${StreamType}`;
|
|
543
555
|
}
|
|
544
556
|
|
|
545
557
|
interface DeviceFilter {
|
|
546
558
|
/** If set, only audio devices whose active state matches this value will satisfy the filter. */
|
|
547
559
|
isActive?: boolean;
|
|
548
560
|
/** If set, only audio devices whose stream type is included in this list will satisfy the filter. */
|
|
549
|
-
streamTypes?: StreamType[];
|
|
561
|
+
streamTypes?: `${StreamType}`[];
|
|
550
562
|
}
|
|
551
563
|
|
|
552
564
|
interface DeviceIdLists {
|
|
@@ -602,7 +614,7 @@ export namespace Browser {
|
|
|
602
614
|
/** Whether or not the stream is now muted. */
|
|
603
615
|
isMuted: boolean;
|
|
604
616
|
/** The type of the stream for which the mute value changed. The updated mute value applies to all devices with this stream type. */
|
|
605
|
-
streamType: StreamType
|
|
617
|
+
streamType: `${StreamType}`;
|
|
606
618
|
}
|
|
607
619
|
|
|
608
620
|
/** Type of stream an audio device provides. */
|
|
@@ -613,14 +625,17 @@ export namespace Browser {
|
|
|
613
625
|
|
|
614
626
|
/**
|
|
615
627
|
* Gets a list of audio devices filtered based on filter.
|
|
628
|
+
* @param filter Device properties by which to filter the list of returned audio devices. If the filter is not set or set to `{}`, returned device list will contain all available audio devices.
|
|
629
|
+
*
|
|
616
630
|
* Can return its result via Promise in Manifest V3 or later since Chrome 116.
|
|
617
631
|
*/
|
|
618
632
|
function getDevices(filter?: DeviceFilter): Promise<AudioDeviceInfo[]>;
|
|
619
|
-
function getDevices(filter: DeviceFilter, callback: (devices: AudioDeviceInfo[]) => void): void;
|
|
620
633
|
function getDevices(callback: (devices: AudioDeviceInfo[]) => void): void;
|
|
634
|
+
function getDevices(filter: DeviceFilter | undefined, callback: (devices: AudioDeviceInfo[]) => void): void;
|
|
621
635
|
|
|
622
636
|
/**
|
|
623
637
|
* Gets the system-wide mute state for the specified stream type.
|
|
638
|
+
*
|
|
624
639
|
* Can return its result via Promise in Manifest V3 or later since Chrome 116.
|
|
625
640
|
*/
|
|
626
641
|
function getMute(streamType: `${StreamType}`): Promise<boolean>;
|
|
@@ -628,6 +643,7 @@ export namespace Browser {
|
|
|
628
643
|
|
|
629
644
|
/**
|
|
630
645
|
* Sets lists of active input and/or output devices.
|
|
646
|
+
*
|
|
631
647
|
* Can return its result via Promise in Manifest V3 or later since Chrome 116.
|
|
632
648
|
*/
|
|
633
649
|
function setActiveDevices(ids: DeviceIdLists): Promise<void>;
|
|
@@ -635,6 +651,7 @@ export namespace Browser {
|
|
|
635
651
|
|
|
636
652
|
/**
|
|
637
653
|
* Sets mute state for a stream type. The mute state will apply to all audio devices with the specified audio stream type.
|
|
654
|
+
*
|
|
638
655
|
* Can return its result via Promise in Manifest V3 or later since Chrome 116.
|
|
639
656
|
*/
|
|
640
657
|
function setMute(streamType: `${StreamType}`, isMuted: boolean): Promise<void>;
|
|
@@ -642,6 +659,7 @@ export namespace Browser {
|
|
|
642
659
|
|
|
643
660
|
/**
|
|
644
661
|
* Sets the properties for the input or output device.
|
|
662
|
+
*
|
|
645
663
|
* Can return its result via Promise in Manifest V3 or later since Chrome 116.
|
|
646
664
|
*/
|
|
647
665
|
function setProperties(id: string, properties: DeviceProperties): Promise<void>;
|
|
@@ -650,18 +668,18 @@ export namespace Browser {
|
|
|
650
668
|
/**
|
|
651
669
|
* Fired when audio devices change, either new devices being added, or existing devices being removed.
|
|
652
670
|
*/
|
|
653
|
-
const onDeviceListChanged:
|
|
671
|
+
const onDeviceListChanged: events.Event<(devices: AudioDeviceInfo[]) => void>;
|
|
654
672
|
|
|
655
673
|
/**
|
|
656
674
|
* Fired when sound level changes for an active audio device.
|
|
657
675
|
*/
|
|
658
|
-
const onLevelChanged:
|
|
676
|
+
const onLevelChanged: events.Event<(event: LevelChangedEvent) => void>;
|
|
659
677
|
|
|
660
678
|
/**
|
|
661
679
|
* Fired when the mute state of the audio input or output changes.
|
|
662
680
|
* Note that mute state is system-wide and the new value applies to every audio device with specified stream type.
|
|
663
681
|
*/
|
|
664
|
-
const onMuteChanged:
|
|
682
|
+
const onMuteChanged: events.Event<(event: MuteChangedEvent) => void>;
|
|
665
683
|
}
|
|
666
684
|
|
|
667
685
|
////////////////////
|
|
@@ -2904,20 +2922,59 @@ export namespace Browser {
|
|
|
2904
2922
|
injectedScript?: string | undefined;
|
|
2905
2923
|
}
|
|
2906
2924
|
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2925
|
+
type EvaluationExceptionInfo =
|
|
2926
|
+
| {
|
|
2927
|
+
/**
|
|
2928
|
+
* Set if the error occurred on the DevTools side before the expression is evaluated.
|
|
2929
|
+
*
|
|
2930
|
+
* If `isError` is set to true, a DevTools-side error has occurred, and `code` is set to an error code.
|
|
2931
|
+
*
|
|
2932
|
+
* See the docs on `isException` for more details on parsing this object.
|
|
2933
|
+
*/
|
|
2934
|
+
isError: true;
|
|
2935
|
+
/** Set if the error occurred on the DevTools side before the expression is evaluated. */
|
|
2936
|
+
code: string;
|
|
2937
|
+
/** Set if the error occurred on the DevTools side before the expression is evaluated. */
|
|
2938
|
+
description: string;
|
|
2939
|
+
/** Set if the error occurred on the DevTools side before the expression is evaluated, contains the array of the values that may be substituted into the description string to provide more information about the cause of the error. */
|
|
2940
|
+
details: any[];
|
|
2941
|
+
/**
|
|
2942
|
+
* Set if the evaluated code produces an unhandled exception.
|
|
2943
|
+
*
|
|
2944
|
+
* If `isException` is non-null but not true, and `isError` is true, a DevTools-side error has occurred, and `code` is set to an error code.
|
|
2945
|
+
*
|
|
2946
|
+
* If `isException` is set to true, a JavaScript error has occurred, and `value` is set to the string value of the thrown object.
|
|
2947
|
+
*/
|
|
2948
|
+
isException?: undefined;
|
|
2949
|
+
/** Set if the evaluated code produces an unhandled exception. */
|
|
2950
|
+
value?: undefined;
|
|
2951
|
+
}
|
|
2952
|
+
| {
|
|
2953
|
+
/**
|
|
2954
|
+
* Set if the error occurred on the DevTools side before the expression is evaluated.
|
|
2955
|
+
*
|
|
2956
|
+
* If `isError` is set to true, a DevTools-side error has occurred, and `code` is set to an error code.
|
|
2957
|
+
*
|
|
2958
|
+
* See the docs on `isException` for more details on parsing this object.
|
|
2959
|
+
*/
|
|
2960
|
+
isError?: undefined;
|
|
2961
|
+
/** Set if the error occurred on the DevTools side before the expression is evaluated. */
|
|
2962
|
+
code?: undefined;
|
|
2963
|
+
/** Set if the error occurred on the DevTools side before the expression is evaluated. */
|
|
2964
|
+
description?: undefined;
|
|
2965
|
+
/** Set if the error occurred on the DevTools side before the expression is evaluated, contains the array of the values that may be substituted into the description string to provide more information about the cause of the error. */
|
|
2966
|
+
details?: undefined;
|
|
2967
|
+
/**
|
|
2968
|
+
* Set if the evaluated code produces an unhandled exception.
|
|
2969
|
+
*
|
|
2970
|
+
* If `isException` is non-null but not true, and `isError` is true, a DevTools-side error has occurred, and `code` is set to an error code.
|
|
2971
|
+
*
|
|
2972
|
+
* If `isException` is set to true, a JavaScript error has occurred, and `value` is set to the string value of the thrown object.
|
|
2973
|
+
*/
|
|
2974
|
+
isException: true;
|
|
2975
|
+
/** Set if the evaluated code produces an unhandled exception. */
|
|
2976
|
+
value: string;
|
|
2977
|
+
};
|
|
2921
2978
|
|
|
2922
2979
|
/** The ID of the tab being inspected. This ID may be used with {@link Browser.tabs} API. */
|
|
2923
2980
|
const tabId: number;
|
|
@@ -2937,15 +2994,23 @@ export namespace Browser {
|
|
|
2937
2994
|
function eval<T = { [key: string]: unknown }>(
|
|
2938
2995
|
expression: string,
|
|
2939
2996
|
options?: EvalOptions,
|
|
2940
|
-
): Promise<
|
|
2997
|
+
): Promise<T>;
|
|
2941
2998
|
function eval<T = { [key: string]: unknown }>(
|
|
2942
2999
|
expression: string,
|
|
2943
|
-
callback
|
|
3000
|
+
callback: (
|
|
3001
|
+
...args:
|
|
3002
|
+
| [result: T, exceptionInfo: undefined]
|
|
3003
|
+
| [result: undefined, exceptionInfo: EvaluationExceptionInfo]
|
|
3004
|
+
) => void,
|
|
2944
3005
|
): void;
|
|
2945
3006
|
function eval<T = { [key: string]: unknown }>(
|
|
2946
3007
|
expression: string,
|
|
2947
3008
|
options: EvalOptions | undefined,
|
|
2948
|
-
callback
|
|
3009
|
+
callback: (
|
|
3010
|
+
...args:
|
|
3011
|
+
| [result: T, exceptionInfo: undefined]
|
|
3012
|
+
| [result: undefined, exceptionInfo: EvaluationExceptionInfo]
|
|
3013
|
+
) => void,
|
|
2949
3014
|
): void;
|
|
2950
3015
|
|
|
2951
3016
|
/**
|