@wxt-dev/browser 0.0.310-alpha1
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/LICENSE +21 -0
- package/README.md +58 -0
- package/package.json +49 -0
- package/src/__tests__/index.test.ts +23 -0
- package/src/gen/chrome-cast/index.d.ts +1159 -0
- package/src/gen/har-format/index.d.ts +9 -0
- package/src/gen/index.d.ts +15110 -0
- package/src/index.d.ts +4 -0
- package/src/index.mjs +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Aaron
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# `@wxt-dev/browser`
|
|
2
|
+
|
|
3
|
+
Provides access to the `browser` or `chrome` extension APIs and related types.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { browser, Browser } from '@wxt-dev/browser';
|
|
7
|
+
// Or if you're using WXT:
|
|
8
|
+
// import { browser, Browser } from 'wxt/browser';
|
|
9
|
+
|
|
10
|
+
console.log(browser.runtime.id);
|
|
11
|
+
|
|
12
|
+
const onMessage = (message: any, sender: Browser.runtime.MessageSender) => {
|
|
13
|
+
console.log(message);
|
|
14
|
+
};
|
|
15
|
+
browser.runtime.onMessage.addListener(onMessage);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
If you're using WXT, this package is already installed, you don't need to install it manually.
|
|
21
|
+
|
|
22
|
+
Otherwise, you can install the package from NPM:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
pnpm install @wxt-dev/browser
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Upgrading to Latest Types
|
|
29
|
+
|
|
30
|
+
Just run:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
pnpm upgrade @wxt-dev/browser
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
This should update both the manually installed version and the subdependency inside WXT.
|
|
37
|
+
|
|
38
|
+
## Contributing
|
|
39
|
+
|
|
40
|
+
### Code Generation
|
|
41
|
+
|
|
42
|
+
Types are generated based on the `@types/chrome` package, and with modifications specifically for use with WXT.
|
|
43
|
+
|
|
44
|
+
### Updating `@types/chrome` Version
|
|
45
|
+
|
|
46
|
+
You don't need to do anything! A github action is ran every day to generate and publish this package using the latest `@types/chrome` version.
|
|
47
|
+
|
|
48
|
+
You can manually generate types via:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
pnpm gen
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Why not just use `@types/chrome`?
|
|
55
|
+
|
|
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
|
+
|
|
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.
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wxt-dev/browser",
|
|
3
|
+
"description": "Provides a cross-browser API for using extension APIs and types based on @types/chrome",
|
|
4
|
+
"version": "0.0.310-alpha1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "src/index.mjs",
|
|
7
|
+
"types": "src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"import": "./src/index.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/wxt-dev/wxt.git",
|
|
20
|
+
"directory": "packages/browser"
|
|
21
|
+
},
|
|
22
|
+
"author": {
|
|
23
|
+
"name": "Aaron Klinker",
|
|
24
|
+
"email": "aaronklinker1+wxt@gmail.com"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"files": [
|
|
28
|
+
"src"
|
|
29
|
+
],
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@aklinker1/check": "^1.4.5",
|
|
32
|
+
"@types/chrome": "0.0.310",
|
|
33
|
+
"fs-extra": "^11.2.0",
|
|
34
|
+
"nano-spawn": "^0.2.0",
|
|
35
|
+
"publint": "^0.2.12",
|
|
36
|
+
"tsx": "4.19.3",
|
|
37
|
+
"typescript": "^5.6.3",
|
|
38
|
+
"vitest": "^3.0.7"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@types/filesystem": "*",
|
|
42
|
+
"@types/har-format": "*"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"gen": "tsx scripts/generate.ts",
|
|
47
|
+
"check": "check"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="chrome" />
|
|
2
|
+
import { describe, expectTypeOf, it } from 'vitest';
|
|
3
|
+
import { browser, Browser } from '../index';
|
|
4
|
+
|
|
5
|
+
describe('browser', () => {
|
|
6
|
+
describe('types', () => {
|
|
7
|
+
it('should provide types via the Browser import', () => {
|
|
8
|
+
expectTypeOf<Browser.runtime.MessageSender>().toMatchTypeOf<chrome.runtime.MessageSender>();
|
|
9
|
+
expectTypeOf<Browser.storage.AreaName>().toMatchTypeOf<chrome.storage.AreaName>();
|
|
10
|
+
expectTypeOf<Browser.i18n.LanguageDetectionResult>().toMatchTypeOf<chrome.i18n.LanguageDetectionResult>();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should provide values via the browser import', () => {
|
|
14
|
+
expectTypeOf(browser.runtime.id).toMatchTypeOf<string>();
|
|
15
|
+
expectTypeOf(
|
|
16
|
+
browser.storage.local,
|
|
17
|
+
).toMatchTypeOf<Browser.storage.StorageArea>();
|
|
18
|
+
expectTypeOf(
|
|
19
|
+
browser.i18n.detectLanguage('Hello, world!'),
|
|
20
|
+
).resolves.toMatchTypeOf<chrome.i18n.LanguageDetectionResult>();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|