@wxt-dev/browser 0.2.9 → 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 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 nested namespace approach, it's not possible to override the types for those functions.
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.2.9",
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.2.9",
28
+ "@types/chrome": "0.3.0",
29
29
  "@types/node": "^22",
30
30
  "typescript": "^6.0.3",
31
31
  "vitest": "^4.1.10"
@@ -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: Browser.events.Event<(devices: AudioDeviceInfo[]) => void>;
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: Browser.events.Event<(event: LevelChangedEvent) => void>;
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: Browser.events.Event<(event: MuteChangedEvent) => void>;
682
+ const onMuteChanged: events.Event<(event: MuteChangedEvent) => void>;
665
683
  }
666
684
 
667
685
  ////////////////////