From 5c8a743cb2d7f2d8ec8239c80d3babecdab963d9 Mon Sep 17 00:00:00 2001 From: Luca Greco Date: Mon, 23 Dec 2019 13:09:26 +0100 Subject: [PATCH] doc: Add section related to basic setup with ES6 module loader (#216) --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index d52c4e6..e9786a6 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Table of contents * [Supported Browsers](#supported-browsers) * [Installation](#installation) * [Basic Setup](#basic-setup) + * [Basic Setup with ES6 module loader](#basic-setup-with-es6-module-loader) * [Basic Setup with module bundlers](#basic-setup-with-module-bundlers) * [Usage with webpack without bundling](#usage-with-webpack-without-bundling) * [Using the Promise-based APIs](#using-the-promise-based-apis) @@ -117,6 +118,31 @@ browser.tabs.executeScript({file: "content.js"}).then(result => { }); ``` +### Basic Setup with ES6 module loader + +The polyfill can also be loaded using the native ES6 module loader available in +the recent browsers versions. + +Be aware that the polyfill module does not export the `browser` API object, +but defines the `browser` object in the global namespace (i.e. `window`). + +```html + + + + + + + + +``` + +```javascript +// In background.js (loaded after browser-polyfill.js) the `browser` +// API object is already defined and provides the promise-based APIs. +browser.runtime.onMessage.addListener(...); +``` + ### Basic Setup with module bundlers This library is built as a **UMD module** (Universal Module Definition), and so it can also be used with module bundlers (and explicitly tested on both **webpack** and **browserify**) or AMD module loaders.