UNPKG

wxt

Version:

⚡ Next-gen Web Extension Framework

30 lines (29 loc) 851 B
import { browser } from "wxt/browser"; import { applyPosition, createMountFunctions, mountUi } from "./shared.mjs"; export function createIframeUi(ctx, options) { const wrapper = document.createElement("div"); const iframe = document.createElement("iframe"); iframe.src = browser.runtime.getURL(options.page); wrapper.appendChild(iframe); let mounted = void 0; const mount = () => { applyPosition(wrapper, iframe, options); mountUi(wrapper, options); mounted = options.onMount?.(wrapper, iframe); }; const remove = () => { options.onRemove?.(mounted); wrapper.remove(); mounted = void 0; }; const mountFunctions = createMountFunctions({ mount, remove }, options); ctx.onInvalidated(remove); return { get mounted() { return mounted; }, iframe, wrapper, ...mountFunctions }; }