Registry / webextension-polyfill-global

webextension-polyfill-global

JSON →
library0.10.1-1jsnpmunverified

webextension-polyfill-global is a utility package designed to make Mozilla's `webextension-polyfill` readily available as a global `browser` object within web extensions, even when using bundlers like Webpack or Parcel. It addresses a known issue where the upstream `webextension-polyfill` can be challenging to import as a true global polyfill, often requiring manual `import()` calls or complex bundler configurations. This package simplifies that process by directly making the polyfill globally accessible upon import. The current stable version is 0.10.1-1. As a wrapper, its release cadence is typically tied to updates in the core `webextension-polyfill` or improvements in its global registration mechanism, though it has seen consistent maintenance. Its key differentiator is its singular focus on providing a simple, fire-and-forget global registration for the browser API, streamlining development for extension authors who prefer the `browser` global over explicit imports everywhere.

npm install webextension-polyfill-global
INSTALL
IMPORT
SIG · WEBEXTENSION-POLYF
W
webextension-polyfill-global
javascriptv0.10.1-1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Side Effect Import
import 'webextension-polyfill-global';
import { browser } from 'webextension-polyfill-global';
This package is imported for its side effects, which register the `browser` global. It does not export any named symbols directly.

Demonstrates how to import the polyfill and immediately use the global `browser` API.

import 'webextension-polyfill-global'; // Now, the 'browser' global API is available async function getActiveTabUrl() { if (typeof browser !== 'undefined' && browser.tabs) { try { const tabs = await browser.tabs.query({ active: true, currentWindow: true }); if (tabs.length > 0) { console.log('Active tab URL:', tabs[0].url); // Example: Send a message to the active tab's content script await browser.tabs.sendMessage(tabs[0].id, { greeting: 'hello from background' }); } } catch (error) { console.error('Error getting active tab URL:', error); } } else { console.warn('WebExtension polyfill or browser API not available.'); } } getActiveTabUrl();
Debug
Known issues
gotchaThis package is primarily a wrapper for `webextension-polyfill`. Ensure `webextension-polyfill` is installed in your project, as this wrapper expects its functionality to be available.
fix
Run `npm install webextension-polyfill` alongside `webextension-polyfill-global`.
affects: >=0.1.0
gotchaWhen using TypeScript, you need to install `@types/webextension-polyfill` as a dev dependency to get global type definitions for the `browser` object, even though this package provides the runtime global.
fix
Run `npm install @types/webextension-polyfill -D`.
affects: >=0.1.0
gotchaThe purpose of this package is to make `browser` available globally. If your project explicitly imports `browser` from `webextension-polyfill` (e.g., `import { browser } from 'webextension-polyfill';`), this package might create redundancy or conflict if not managed carefully. Choose one approach.
fix
Decide on a single strategy: either use this package for a global `browser` object and avoid explicit imports, or manage `webextension-polyfill` imports directly without `webextension-polyfill-global`.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'tabs') or 'browser' is undefined
The webextension-polyfill-global import was not executed, or not executed early enough, before attempting to access the `browser` global.
fix
Ensure `import 'webextension-polyfill-global';` is at the very top of your entry file (e.g., background.js, popup.js) or any script where the global `browser` object is needed.
TS2304: Cannot find name 'browser'.
TypeScript compiler cannot find the global type definition for 'browser'.
fix
Install the official TypeScript types: `npm install @types/webextension-polyfill -D`.
Upgrade
Version history
0.10.1-1latest on npm
Audit
Dependencies
webextension-polyfillrequiredThis package wraps and makes available the functionality of `webextension-polyfill`.
@types/webextension-polyfilloptionalProvides TypeScript type definitions for the global `browser` object. Required for TypeScript projects.
Agent activity
4 hits · last 30 days
node
4
Resources
webextension-polyfill-global — npm install webextension-polyfill-global · libregistry