Coder Social home page Coder Social logo

msanguineti / webextension-polyfill-ts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lusito/webextension-polyfill-ts

0.0 1.0 0.0 754 KB

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

License: zlib License

TypeScript 59.95% JavaScript 40.05%

webextension-polyfill-ts's Introduction

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.

webextension-polyfill-ts's People

Contributors

bboydflo avatar jpd-dds avatar lusito avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.