Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

webextension-polyfill-ts

0.8.9 • Public • Published

Web-Extension Polyfill for TypeScript

This is a TypeScript ready "wrapper" for the WebExtension browser API Polyfill by Mozilla.

  • It does include webextension-polyfill, so no need to manually add it.
  • It is generated from these mozilla schema (.json) files:

How to use:

This guide assumes you are building a web-extension using npm and webpack. If you are looking for an example use-case, check out the development branch of my web-extension Forget Me Not.

  • 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:

import { browser, Cookies } from "webextension-polyfill-ts";
const 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.

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

Help

If you have problems, questions or other feedback, please create an issue here on Github.

License

My generator code of this project has been released under the zlib/libpng 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.

install

npm i webextension-polyfill-ts

Downloadsweekly downloads

161

version

0.8.9

license

Zlib

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability