Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webextension-polyfill-ts

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webextension-polyfill-ts

webextension-polyfill for TypeScript

  • 0.20.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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, parcel or similar. 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 { 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 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

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.

Keywords

FAQs

Package last updated on 12 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc