@webext-core/isolated-element
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

@webext-core/isolated-element

Isolate content script UI's styles from the parent page and control event bubbling to the host page. Supports all browsers (Chrome, Firefox, Safari).

pnpm i @webext-core/isolated-element
import { createIsolatedElement } from '@webext-core/isolated-element';
import browser from 'webextension-polyfill';

function mountUI(root: HtmlElement) {
  const text = document.createElement('p');
  text.textContent = 'Isolated text';
  root.appendChild(text);
}

const { parentElement, isolatedElement } = await createIsolatedElement({
  name: 'some-name',
  css: {
    url: browser.runtime.getURL('/path/to/styles.css'),
  },
  isolateEvents: true, // or array of event names to isolate, e.g., ['click', 'keydown']
});

mountUi(isolatedElement);
document.body.appendChild(parentElement);

Get Started

See documentation to get started!

/@webext-core/isolated-element/

    Package Sidebar

    Install

    npm i @webext-core/isolated-element

    Weekly Downloads

    5,187

    Version

    1.1.2

    License

    MIT

    Unpacked Size

    16.4 kB

    Total Files

    7

    Last publish

    Collaborators

    • _aklinker1