wxt 0.19.3 → 0.19.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ import type { WxtRuntime, WxtI18n } from './index';
1
2
  /**
2
3
  * EXPERIMENTAL
3
4
  *
@@ -5,10 +6,6 @@
5
6
  *
6
7
  * @module wxt/browser/chrome
7
8
  */
8
- export interface WxtRuntime {
9
- }
10
- export interface WxtI18n {
11
- }
12
9
  export type Chrome = typeof chrome;
13
10
  export type WxtBrowser = Omit<Chrome, 'runtime' | 'i18n'> & {
14
11
  runtime: WxtRuntime & Omit<Chrome['runtime'], 'getURL'>;
@@ -3,14 +3,14 @@
3
3
  *
4
4
  * @module wxt/browser
5
5
  */
6
- import { Browser, Runtime, I18n } from 'webextension-polyfill';
7
- export interface AugmentedBrowser extends Browser {
8
- runtime: WxtRuntime;
9
- i18n: WxtI18n;
6
+ import { Browser } from 'webextension-polyfill';
7
+ export type AugmentedBrowser = Omit<Browser, 'runtime' | 'i18n'> & {
8
+ runtime: WxtRuntime & Omit<Browser['runtime'], 'getURL'>;
9
+ i18n: WxtI18n & Omit<Browser['i18n'], 'getMessage'>;
10
+ };
11
+ export interface WxtRuntime {
10
12
  }
11
- export interface WxtRuntime extends Runtime.Static {
12
- }
13
- export interface WxtI18n extends I18n.Static {
13
+ export interface WxtI18n {
14
14
  }
15
15
  export declare const browser: AugmentedBrowser;
16
16
  /** @ignore */
@@ -71,7 +71,7 @@ export type IframeContentScriptUiOptions<TMounted> = ContentScriptUiOptions<TMou
71
71
  * The path to the HTML page that will be shown in the iframe. This string is passed into
72
72
  * `browser.runtime.getURL`.
73
73
  */
74
- page: PublicPath;
74
+ page: import('wxt/browser').HtmlPublicPath;
75
75
  /**
76
76
  * Callback executed when mounting the UI. Use this function to customize the iframe or wrapper
77
77
  * element's appearance. It is called every time `ui.mount()` is called.
@@ -5,3 +5,4 @@
5
5
  */
6
6
  export * from './content-scripts';
7
7
  export * from './app-config';
8
+ export * from './inject-script';
@@ -1,2 +1,3 @@
1
1
  export * from "./content-scripts/index.mjs";
2
2
  export * from "./app-config.mjs";
3
+ export * from "./inject-script.mjs";
@@ -0,0 +1,18 @@
1
+ export type ScriptPublicPath = Extract<import('wxt/browser').PublicPath, `${string}.js`>;
2
+ /**
3
+ * This function can only be called inside content scripts.
4
+ *
5
+ * Inject an unlisted script into the page. Scripts are added to the `<head>`
6
+ * element or `document.documentElement` if there is no head.
7
+ *
8
+ * Make sure to add the injected script to your manifest's
9
+ * `web_accessible_resources`.
10
+ */
11
+ export declare function injectScript(path: ScriptPublicPath, options?: InjectScriptOptions): Promise<void>;
12
+ export interface InjectScriptOptions {
13
+ /**
14
+ * By default, the injected script is removed from the DOM after being
15
+ * injected. To disable this behavior, set this flag to true.
16
+ */
17
+ keepInDom?: boolean;
18
+ }
@@ -0,0 +1,14 @@
1
+ import { browser } from "wxt/browser";
2
+ export async function injectScript(path, options) {
3
+ const url = browser.runtime.getURL(path);
4
+ const script = document.createElement("script");
5
+ if (browser.runtime.getManifest().manifest_version === 2) {
6
+ script.innerHTML = await fetch(url).then((res) => res.text());
7
+ } else {
8
+ script.src = url;
9
+ }
10
+ if (!options?.keepInDom) {
11
+ script.onload = () => script.remove();
12
+ }
13
+ (document.head ?? document.documentElement).append(script);
14
+ }
@@ -15,7 +15,17 @@ import { wxt } from "../../wxt.mjs";
15
15
  import { createExtensionEnvironment } from "../environments/index.mjs";
16
16
  export async function findEntrypoints() {
17
17
  await fs.mkdir(wxt.config.wxtDir, { recursive: true });
18
- await fs.writeJson(resolve(wxt.config.wxtDir, "tsconfig.json"), {});
18
+ try {
19
+ await fs.writeJson(
20
+ resolve(wxt.config.wxtDir, "tsconfig.json"),
21
+ {},
22
+ { flag: "wx" }
23
+ );
24
+ } catch (err) {
25
+ if (!(err instanceof Error) || !("code" in err) || err.code !== "EEXIST") {
26
+ throw err;
27
+ }
28
+ }
19
29
  const relativePaths = await glob(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
20
30
  cwd: wxt.config.entrypointsDir
21
31
  });
@@ -50,9 +50,9 @@ async function getPathsDeclarationEntry(entrypoints) {
50
50
  await wxt.hooks.callHook("prepare:publicPaths", wxt, paths);
51
51
  const unions = paths.map(normalizePath).sort().map((path2) => ` | "/${path2}"`).join("\n");
52
52
  const template = `// Generated by wxt
53
- import "${wxt.config.browserModule}";
53
+ import "wxt/browser";
54
54
 
55
- declare module "${wxt.config.browserModule}" {
55
+ declare module "wxt/browser" {
56
56
  export type PublicPath =
57
57
  {{ union }}
58
58
  type HtmlPublicPath = Extract<PublicPath, \`\${string}.html\`>
@@ -71,9 +71,9 @@ declare module "${wxt.config.browserModule}" {
71
71
  async function getI18nDeclarationEntry() {
72
72
  const defaultLocale = wxt.config.manifest.default_locale;
73
73
  const template = `// Generated by wxt
74
- import "${wxt.config.browserModule}";
74
+ import "wxt/browser";
75
75
 
76
- declare module "${wxt.config.browserModule}" {
76
+ declare module "wxt/browser" {
77
77
  /**
78
78
  * See https://developer.chrome.com/docs/extensions/reference/i18n/#method-getMessage
79
79
  */
@@ -134,7 +134,6 @@ export async function resolveConfig(inlineConfig, command) {
134
134
  userConfigMetadata: userConfigMetadata ?? {},
135
135
  alias,
136
136
  extensionApi,
137
- browserModule: extensionApi === "chrome" ? "wxt/browser/chrome" : "wxt/browser",
138
137
  entrypointLoader: mergedConfig.entrypointLoader ?? "vite-node",
139
138
  experimental: defu(mergedConfig.experimental, {}),
140
139
  dev: {
@@ -1481,7 +1481,6 @@ export declare const fakeResolvedConfig: (overrides?: {
1481
1481
  [x: string]: string | undefined;
1482
1482
  } | undefined;
1483
1483
  extensionApi?: "webextension-polyfill" | "chrome" | undefined;
1484
- browserModule?: "wxt/browser" | "wxt/browser/chrome" | undefined;
1485
1484
  entrypointLoader?: "vite-node" | "jiti" | undefined;
1486
1485
  experimental?: {} | undefined;
1487
1486
  dev?: {
@@ -3037,7 +3036,6 @@ export declare const fakeWxt: (overrides?: {
3037
3036
  [x: string]: string | undefined;
3038
3037
  } | undefined;
3039
3038
  extensionApi?: "webextension-polyfill" | "chrome" | undefined;
3040
- browserModule?: "wxt/browser" | "wxt/browser/chrome" | undefined;
3041
3039
  entrypointLoader?: "vite-node" | "jiti" | undefined;
3042
3040
  experimental?: {} | undefined;
3043
3041
  dev?: {
@@ -247,7 +247,6 @@ export const fakeResolvedConfig = fakeObjectCreator(() => {
247
247
  userConfigMetadata: {},
248
248
  alias: {},
249
249
  extensionApi: "webextension-polyfill",
250
- browserModule: "wxt/browser",
251
250
  entrypointLoader: "vite-node",
252
251
  experimental: {},
253
252
  dev: {
package/dist/types.d.ts CHANGED
@@ -1101,7 +1101,6 @@ export interface ResolvedConfig {
1101
1101
  */
1102
1102
  alias: Record<string, string>;
1103
1103
  extensionApi: 'webextension-polyfill' | 'chrome';
1104
- browserModule: 'wxt/browser' | 'wxt/browser/chrome';
1105
1104
  entrypointLoader: 'vite-node' | 'jiti';
1106
1105
  experimental: {};
1107
1106
  dev: {
package/dist/version.mjs CHANGED
@@ -1 +1 @@
1
- export const version = "0.19.3";
1
+ export const version = "0.19.4";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wxt",
3
3
  "type": "module",
4
- "version": "0.19.3",
4
+ "version": "0.19.4",
5
5
  "description": "Next gen framework for developing web extensions",
6
6
  "repository": {
7
7
  "type": "git",