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

webextension-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webextension-polyfill

A lightweight polyfill library for Promise-based WebExtension APIs in Chrome.

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is webextension-polyfill?

The webextension-polyfill npm package provides a standardized API for developing browser extensions that work across different browsers. It offers a promise-based interface to the WebExtension APIs, making it easier to write consistent and maintainable code.

What are webextension-polyfill's main functionalities?

Browser Tabs

This feature allows you to interact with browser tabs. The code sample demonstrates how to get the current active tab in the current window.

const browser = require('webextension-polyfill');

async function getCurrentTab() {
  let tabs = await browser.tabs.query({ active: true, currentWindow: true });
  return tabs[0];
}

getCurrentTab().then(tab => console.log(tab));

Storage

This feature allows you to store and retrieve data using the browser's storage API. The code sample demonstrates how to save a key-value pair to local storage and then retrieve it.

const browser = require('webextension-polyfill');

async function saveToStorage(key, value) {
  await browser.storage.local.set({ [key]: value });
}

async function getFromStorage(key) {
  let result = await browser.storage.local.get(key);
  return result[key];
}

saveToStorage('exampleKey', 'exampleValue');
getFromStorage('exampleKey').then(value => console.log(value));

Messaging

This feature allows you to send messages between different parts of your extension, such as between a background script and a content script. The code sample demonstrates how to set up a message listener in the background script and send a message from the content script.

const browser = require('webextension-polyfill');

// Background script
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
  if (message.greeting === 'hello') {
    sendResponse({ response: 'hi' });
  }
});

// Content script
browser.runtime.sendMessage({ greeting: 'hello' }).then(response => {
  console.log(response.response);
});

Other packages similar to webextension-polyfill

FAQs

Package last updated on 25 Sep 2017

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