# webextension-polyfill-ts

> webextension-polyfill for TypeScript

Latest version **0.26.0** (published 2021-07-03) · Zlib license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install webextension-polyfill-ts
pnpm add webextension-polyfill-ts
yarn add webextension-polyfill-ts
bun add webextension-polyfill-ts
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.26.0 |
| Published | 2021-07-03 |
| First published | 2018-01-20 |
| Weekly downloads | 0 |
| License | Zlib |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 432.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 398 |
| Author | Santo Pfingsten |
| Maintainers | lusito |
| Keywords | TypeScript, webextension, polyfill |

## Links

- npm: https://www.npmjs.com/package/webextension-polyfill-ts
- Repository: https://github.com/Lusito/webextension-polyfill-ts
- Issues: https://github.com/Lusito/webextension-polyfill-ts/issues
- npm.io page: https://npm.io/package/webextension-polyfill-ts

## Dependencies (1)

- [webextension-polyfill](https://npm.io/package/webextension-polyfill.md) ^0.8.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.26.0 (latest) — 2021-07-03
- 0.25.0 — 2021-02-14
- 0.24.0 — 2021-01-31
- 0.22.0 — 2020-11-13
- 0.21.0 — 2020-10-25
- 0.20.0 — 2020-09-12
- 0.19.0 — 2020-06-28
- 0.18.0 — 2020-06-25
- 0.17.0 — 2020-06-06
- 0.16.0 — 2020-05-23
- 0.15.0 — 2020-05-02
- 0.14.0 — 2020-03-25
- 0.13.0 — 2020-03-07
- 0.12.0 — 2020-01-26
- 0.11.0 — 2019-11-12
- … 12 more at https://npm.io/package/webextension-polyfill-ts/versions

## README

# Web-Extension Polyfill for TypeScript

This is a TypeScript ready "wrapper" for the [WebExtension browser API Polyfill](https://github.com/mozilla/webextension-polyfill) by Mozilla.
* It does include webextension-polyfill, so no need to manually add it.
* It is generated from these mozilla schema (.json) files:
  * [toolkit](https://hg.mozilla.org/integration/autoland/raw-file/tip/toolkit/components/extensions/schemas/)
  * [browser](https://hg.mozilla.org/integration/autoland/raw-file/tip/browser/components/extensions/schemas/)

## How to use:
This guide assumes you are building a web-extension using npm and webpack, parcel or similar.
If you are looking for an example use-case, check out the development branch of my web-extension [Forget Me Not](https://github.com/lusito/forget-me-not/tree/develop).

* `npm install --save-dev webextension-polyfill-ts`
* `import { browser } from "webextension-polyfill-ts";`
  * Use this to access the browser API.
  * If the current environment does not supply a global window object, the exported browser object will be a dummy object, which you can use for unit tests.

If you want to use the exported types in your code, simply import them like this:
```typescript
import { Cookies } from "webextension-polyfill-ts";

function inspectCookie(cookie: Cookies.Cookie) {
    //...
}
```

All types are inside their respective namespace:
* Namespaces are named like their API, but with the first character as upper-case.
  * For example `browser.cookies` types are in the `Cookies` namespace
* Nested namespaces will remove the dot and have the first character after the dot as upper-case.
  * For example `browser.devtools.inspectedWindow` types are in the `DevtoolsInspectedWindow` namespace.

## Unit Testing
Consider [mockzilla-webextension](https://lusito.github.io/mockzilla-webextension/) for unit-testing. It combines all the types this package provides with some nifty mocking functionality.

## Issues
There are still some issues left:
* Since the schema .json files have a lot of anonymous nested types, some of the types will have generated names.
  * These might change in the future, since the generated names are far from perfect.
* Some of the schema files are incomplete.. for example in some places, a null value is allowed, yet the schema file doesn't say anything about it. I have fixed some of these, but there are probably more.
* Not every API has been tested.

## Contributing Guidelines:

See [CONTRIBUTING.md](CONTRIBUTING.md)

## Help
If you have problems, questions or other feedback, please [create an issue](https://github.com/Lusito/webextension-polyfill-ts/issues) here on Github.

## License
My generator code of this project has been released under the [zlib/libpng License](https://github.com/Lusito/webextension-polyfill-ts/blob/master/LICENSE)

The schema files from mozilla however have defined their own licences, which will be exported to the generated .ts files as well.
For example, there are files under the Mozilla Public License and some under a BSD style license.

---
_Source: https://npm.io/package/webextension-polyfill-ts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
