Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@webext-core/isolated-element
Advanced tools
@webext-core/isolated-element
Need to inject a UI onto a webpage from a content script? Isolating your CSS from the webpage's CSS is hard, but that's where this library comes in.
It uses the ShadowRoot
API to create a custom element who's CSS is completely separate from the page it's on.
pnpm i @webext-core/isolated-element
This library doesn't require any of the extension-specific APIs to run, so it can be used outside of web extensions as well.
createIsolatedElement
returns two elements:
parentElement
needs to be added to the DOM where you want your UI to show up.isolatedElement
is where you should mount your UI.Here, we're mounting a Vanilla JS app inside the isolated element.
import { createIsolatedElement } from '@webext-core/isolated-element';
import browser from 'webextension-polyfill';
const = createIsolatedElement({
name: 'some-name',
css: browser.runtime.getURL('/path/to/styles.css'),
}).then(({ parentElement, isolatedElement }) => {
// Mount our UI inside the isolated element
const ui = document.createElement('div');
ui.textContent = 'Isolated UI';
isolatedElement.appendChild(ui);
// Add the UI to the DOM
document.body.append(parentElement);
});
Here's a couple of other ways to mount your UI inside the isolatedElement
:
import { createApp } from 'vue';
import App from './App.vue';
createApp(App).mount(isolatedElement);
import ReactDOM from 'react-dom';
import App from './App.tsx';
ReactDOM.createRoot(isolatedElement).render(<App />);
Option | Type | Required | Default | Description |
---|---|---|---|---|
name | string | ✅ | A unique tag name used when defining the web component used internally. Don't use the same name twice for different UIs | |
css | { url: string } or { textContent: string } | Either the URL to a CSS file of the text contents of a CSS file | ||
mode | "open" or "closed" | "closed" | See ShadowRoot.mode |
FAQs
Isolate content script UI's styles from the parent page. Supports all browsers (Chrome, Firefox, Safari)
The npm package @webext-core/isolated-element receives a total of 7,786 weekly downloads. As such, @webext-core/isolated-element popularity was classified as popular.
We found that @webext-core/isolated-element demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.