wxt 0.12.1 → 0.12.2-alpha2
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.
- package/dist/browser.d.ts +1 -0
- package/dist/{chunk-ENVSDI4C.js → chunk-LDULNXMK.js} +2 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1 -7
- package/dist/client.js +2 -3
- package/dist/index.cjs +1 -7
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -7
- package/dist/sandbox.d.ts +1 -0
- package/dist/sandbox.js +3 -0
- package/dist/storage.cjs +16 -11
- package/dist/storage.js +6 -1
- package/dist/testing.cjs +1 -1
- package/dist/testing.js +1 -1
- package/dist/virtual/background-entrypoint.js +8 -8
- package/dist/virtual/content-script-isolated-world-entrypoint.js +2 -215
- package/dist/virtual/content-script-main-world-entrypoint.js +1 -1
- package/dist/virtual/mock-browser.js +2 -142
- package/dist/virtual/reload-html.js +2 -2
- package/dist/virtual/unlisted-script-entrypoint.js +1 -1
- package/package.json +4 -2
package/dist/browser.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Browser, Runtime, I18n } from 'webextension-polyfill';
|
|
2
|
+
export { Action, ActivityLog, Alarms, Bookmarks, BrowserAction, BrowserSettings, BrowsingData, CaptivePortal, Clipboard, Commands, ContentScripts, ContextMenus, ContextualIdentities, Cookies, DeclarativeNetRequest, Devtools, Dns, Downloads, Events, Experiments, Extension, ExtensionTypes, Find, GeckoProfiler, History, I18n, Identity, Idle, Management, Manifest, Menus, NetworkStatus, NormandyAddonStudy, Notifications, Omnibox, PageAction, Permissions, Pkcs11, Privacy, Proxy, Runtime, Scripting, Search, Sessions, SidebarAction, Storage, Tabs, Theme, TopSites, Types, Urlbar, UserScripts, WebNavigation, WebRequest, Windows } from 'webextension-polyfill';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @module wxt/browser
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// package.json
|
|
2
|
-
var version = "0.12.
|
|
2
|
+
var version = "0.12.2-alpha2";
|
|
3
3
|
|
|
4
4
|
// src/core/utils/arrays.ts
|
|
5
5
|
function every(array, predicate) {
|
|
@@ -951,7 +951,7 @@ function webextensionPolyfillInlineDeps() {
|
|
|
951
951
|
return {
|
|
952
952
|
name: "wxt:testing-inline-deps",
|
|
953
953
|
config() {
|
|
954
|
-
const wxtModules = ["wxt/browser"
|
|
954
|
+
const wxtModules = ["wxt/browser"];
|
|
955
955
|
return {
|
|
956
956
|
test: {
|
|
957
957
|
server: {
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import "./chunk-VBXJIVYU.js";
|
|
|
4
4
|
import cac from "cac";
|
|
5
5
|
|
|
6
6
|
// package.json
|
|
7
|
-
var version = "0.12.
|
|
7
|
+
var version = "0.12.2-alpha2";
|
|
8
8
|
|
|
9
9
|
// src/core/utils/fs.ts
|
|
10
10
|
import fs from "fs-extra";
|
|
@@ -2933,12 +2933,6 @@ async function cloneProject({
|
|
|
2933
2933
|
).catch(
|
|
2934
2934
|
(err) => consola5.warn("Failed to move _gitignore to .gitignore:", err)
|
|
2935
2935
|
);
|
|
2936
|
-
if (packageManager === "pnpm") {
|
|
2937
|
-
await fs14.writeFile(
|
|
2938
|
-
path6.join(directory, ".npmrc"),
|
|
2939
|
-
"shamefully-hoist=true\n"
|
|
2940
|
-
);
|
|
2941
|
-
}
|
|
2942
2936
|
spinner.succeed();
|
|
2943
2937
|
} catch (err) {
|
|
2944
2938
|
spinner.fail();
|
package/dist/client.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
browser
|
|
3
3
|
} from "./chunk-FNTE2L27.js";
|
|
4
4
|
|
|
5
|
-
// src/
|
|
5
|
+
// src/sandbox/utils/logger.ts
|
|
6
6
|
function print(method, ...args) {
|
|
7
7
|
if (import.meta.env.MODE === "production")
|
|
8
8
|
return;
|
|
@@ -364,12 +364,11 @@ async function loadCss() {
|
|
|
364
364
|
}
|
|
365
365
|
|
|
366
366
|
// src/client/content-scripts/content-script-iframe.ts
|
|
367
|
-
import browser2 from "webextension-polyfill";
|
|
368
367
|
function createContentScriptIframe(ctx, options) {
|
|
369
368
|
const wrapper = document.createElement("div");
|
|
370
369
|
wrapper.classList.add("wxt-iframe-wrapper");
|
|
371
370
|
const iframe = document.createElement("iframe");
|
|
372
|
-
iframe.src =
|
|
371
|
+
iframe.src = browser.runtime.getURL(options.page);
|
|
373
372
|
wrapper.appendChild(iframe);
|
|
374
373
|
const mount = () => {
|
|
375
374
|
applyContentScriptUiPosition(wrapper, iframe, options);
|
package/dist/index.cjs
CHANGED
|
@@ -4334,7 +4334,7 @@ function getChunkSortWeight(filename) {
|
|
|
4334
4334
|
var import_picocolors3 = __toESM(require("picocolors"), 1);
|
|
4335
4335
|
|
|
4336
4336
|
// package.json
|
|
4337
|
-
var version = "0.12.
|
|
4337
|
+
var version = "0.12.2-alpha2";
|
|
4338
4338
|
|
|
4339
4339
|
// src/core/utils/log/printHeader.ts
|
|
4340
4340
|
var import_consola2 = require("consola");
|
|
@@ -5369,12 +5369,6 @@ async function cloneProject({
|
|
|
5369
5369
|
).catch(
|
|
5370
5370
|
(err) => import_consola5.consola.warn("Failed to move _gitignore to .gitignore:", err)
|
|
5371
5371
|
);
|
|
5372
|
-
if (packageManager === "pnpm") {
|
|
5373
|
-
await import_fs_extra14.default.writeFile(
|
|
5374
|
-
import_node_path18.default.join(directory, ".npmrc"),
|
|
5375
|
-
"shamefully-hoist=true\n"
|
|
5376
|
-
);
|
|
5377
|
-
}
|
|
5378
5372
|
spinner.succeed();
|
|
5379
5373
|
} catch (err) {
|
|
5380
5374
|
spinner.fail();
|
package/dist/index.d.cts
CHANGED
|
@@ -62,6 +62,6 @@ declare function prepare(config: InlineConfig): Promise<void>;
|
|
|
62
62
|
*/
|
|
63
63
|
declare function zip(config?: InlineConfig): Promise<string[]>;
|
|
64
64
|
|
|
65
|
-
var version = "0.12.
|
|
65
|
+
var version = "0.12.2-alpha2";
|
|
66
66
|
|
|
67
67
|
export { BuildOutput, ExtensionRunnerConfig, InlineConfig, UserConfig, WxtDevServer, build, clean, createServer, defineConfig, defineRunnerConfig, initialize, prepare, version, zip };
|
package/dist/index.d.ts
CHANGED
|
@@ -62,6 +62,6 @@ declare function prepare(config: InlineConfig): Promise<void>;
|
|
|
62
62
|
*/
|
|
63
63
|
declare function zip(config?: InlineConfig): Promise<string[]>;
|
|
64
64
|
|
|
65
|
-
var version = "0.12.
|
|
65
|
+
var version = "0.12.2-alpha2";
|
|
66
66
|
|
|
67
67
|
export { BuildOutput, ExtensionRunnerConfig, InlineConfig, UserConfig, WxtDevServer, build, clean, createServer, defineConfig, defineRunnerConfig, initialize, prepare, version, zip };
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
rebuild,
|
|
16
16
|
resolvePerBrowserOption,
|
|
17
17
|
version
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-LDULNXMK.js";
|
|
19
19
|
import "./chunk-VBXJIVYU.js";
|
|
20
20
|
|
|
21
21
|
// src/core/build.ts
|
|
@@ -457,12 +457,6 @@ async function cloneProject({
|
|
|
457
457
|
).catch(
|
|
458
458
|
(err) => consola3.warn("Failed to move _gitignore to .gitignore:", err)
|
|
459
459
|
);
|
|
460
|
-
if (packageManager === "pnpm") {
|
|
461
|
-
await fs2.writeFile(
|
|
462
|
-
path2.join(directory, ".npmrc"),
|
|
463
|
-
"shamefully-hoist=true\n"
|
|
464
|
-
);
|
|
465
|
-
}
|
|
466
460
|
spinner.succeed();
|
|
467
461
|
} catch (err) {
|
|
468
462
|
spinner.fail();
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { U as UnlistedScriptDefinition, B as BackgroundDefinition, C as ContentScriptDefinition } from './external-TYmXqKVq.js';
|
|
2
|
+
export * from '@webext-core/match-patterns';
|
|
2
3
|
import 'webextension-polyfill';
|
|
3
4
|
|
|
4
5
|
declare function defineUnlistedScript(main: () => void): UnlistedScriptDefinition;
|
package/dist/sandbox.js
CHANGED
package/dist/storage.cjs
CHANGED
|
@@ -36,11 +36,16 @@ __export(storage_exports, {
|
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(storage_exports);
|
|
38
38
|
var import_unstorage = require("unstorage");
|
|
39
|
+
|
|
40
|
+
// src/browser.ts
|
|
39
41
|
var import_webextension_polyfill = __toESM(require("webextension-polyfill"), 1);
|
|
42
|
+
var browser = import_webextension_polyfill.default;
|
|
43
|
+
|
|
44
|
+
// src/storage.ts
|
|
40
45
|
__reExport(storage_exports, require("unstorage"), module.exports);
|
|
41
46
|
var webExtensionDriver = (0, import_unstorage.defineDriver)((opts) => {
|
|
42
47
|
const checkPermission = () => {
|
|
43
|
-
if (
|
|
48
|
+
if (browser.storage == null)
|
|
44
49
|
throw Error(
|
|
45
50
|
"You must request the 'storage' permission to use webExtensionDriver"
|
|
46
51
|
);
|
|
@@ -57,17 +62,17 @@ var webExtensionDriver = (0, import_unstorage.defineDriver)((opts) => {
|
|
|
57
62
|
name: "web-extension:" + opts.storageArea,
|
|
58
63
|
async hasItem(key) {
|
|
59
64
|
checkPermission();
|
|
60
|
-
const res = await
|
|
65
|
+
const res = await browser.storage[opts.storageArea].get(key);
|
|
61
66
|
return res[key] != null;
|
|
62
67
|
},
|
|
63
68
|
async getItem(key) {
|
|
64
69
|
checkPermission();
|
|
65
|
-
const res = await
|
|
70
|
+
const res = await browser.storage[opts.storageArea].get(key);
|
|
66
71
|
return res[key] ?? null;
|
|
67
72
|
},
|
|
68
73
|
async getItems(items) {
|
|
69
74
|
checkPermission();
|
|
70
|
-
const res = await
|
|
75
|
+
const res = await browser.storage[opts.storageArea].get(
|
|
71
76
|
items.map((item) => item.key)
|
|
72
77
|
);
|
|
73
78
|
return items.map((item) => ({
|
|
@@ -77,7 +82,7 @@ var webExtensionDriver = (0, import_unstorage.defineDriver)((opts) => {
|
|
|
77
82
|
},
|
|
78
83
|
async setItem(key, value) {
|
|
79
84
|
checkPermission();
|
|
80
|
-
await
|
|
85
|
+
await browser.storage[opts.storageArea].set({ [key]: value ?? null });
|
|
81
86
|
},
|
|
82
87
|
async setItems(items) {
|
|
83
88
|
checkPermission();
|
|
@@ -85,33 +90,33 @@ var webExtensionDriver = (0, import_unstorage.defineDriver)((opts) => {
|
|
|
85
90
|
map2[item.key] = item.value ?? null;
|
|
86
91
|
return map2;
|
|
87
92
|
}, {});
|
|
88
|
-
await
|
|
93
|
+
await browser.storage[opts.storageArea].set(map);
|
|
89
94
|
},
|
|
90
95
|
async removeItem(key) {
|
|
91
96
|
checkPermission();
|
|
92
|
-
await
|
|
97
|
+
await browser.storage[opts.storageArea].remove(key);
|
|
93
98
|
},
|
|
94
99
|
async getKeys() {
|
|
95
100
|
checkPermission();
|
|
96
|
-
const all = await
|
|
101
|
+
const all = await browser.storage[opts.storageArea].get();
|
|
97
102
|
return Object.keys(all);
|
|
98
103
|
},
|
|
99
104
|
async clear() {
|
|
100
105
|
checkPermission();
|
|
101
|
-
await
|
|
106
|
+
await browser.storage[opts.storageArea].clear();
|
|
102
107
|
},
|
|
103
108
|
watch(callback) {
|
|
104
109
|
checkPermission();
|
|
105
110
|
_listeners.add(callback);
|
|
106
111
|
if (_listeners.size === 1) {
|
|
107
|
-
|
|
112
|
+
browser.storage[opts.storageArea].onChanged.addListener(
|
|
108
113
|
_storageListener
|
|
109
114
|
);
|
|
110
115
|
}
|
|
111
116
|
return () => {
|
|
112
117
|
_listeners.delete(callback);
|
|
113
118
|
if (_listeners.size === 0) {
|
|
114
|
-
|
|
119
|
+
browser.storage[opts.storageArea].onChanged.removeListener(
|
|
115
120
|
_storageListener
|
|
116
121
|
);
|
|
117
122
|
}
|
package/dist/storage.js
CHANGED
|
@@ -5,7 +5,12 @@ import {
|
|
|
5
5
|
createStorage,
|
|
6
6
|
defineDriver
|
|
7
7
|
} from "unstorage";
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
// src/browser.ts
|
|
10
|
+
import originalBrowser from "webextension-polyfill";
|
|
11
|
+
var browser = originalBrowser;
|
|
12
|
+
|
|
13
|
+
// src/storage.ts
|
|
9
14
|
export * from "unstorage";
|
|
10
15
|
var webExtensionDriver = defineDriver((opts) => {
|
|
11
16
|
const checkPermission = () => {
|
package/dist/testing.cjs
CHANGED
package/dist/testing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/virtual/background-entrypoint.ts
|
|
2
2
|
import definition from "virtual:user-background";
|
|
3
3
|
|
|
4
|
-
// src/
|
|
4
|
+
// src/sandbox/utils/logger.ts
|
|
5
5
|
function print(method, ...args) {
|
|
6
6
|
if (import.meta.env.MODE === "production")
|
|
7
7
|
return;
|
|
@@ -19,7 +19,7 @@ var logger = {
|
|
|
19
19
|
error: (...args) => print(console.error, ...args)
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
// src/
|
|
22
|
+
// src/virtual/utils/setup-web-socket.ts
|
|
23
23
|
function setupWebSocket(onMessage) {
|
|
24
24
|
const serverUrl = `${__DEV_SERVER_PROTOCOL__}//${__DEV_SERVER_HOSTNAME__}:${__DEV_SERVER_PORT__}`;
|
|
25
25
|
logger.debug("Connecting to dev server @", serverUrl);
|
|
@@ -47,19 +47,19 @@ function setupWebSocket(onMessage) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// src/virtual/background-entrypoint.ts
|
|
50
|
-
import browser3 from "
|
|
50
|
+
import { browser as browser3 } from "wxt/browser";
|
|
51
51
|
|
|
52
|
-
// src/
|
|
53
|
-
import browser from "
|
|
52
|
+
// src/virtual/utils/keep-service-worker-alive.ts
|
|
53
|
+
import { browser } from "wxt/browser";
|
|
54
54
|
function keepServiceWorkerAlive() {
|
|
55
55
|
setInterval(async () => {
|
|
56
56
|
await browser.runtime.getPlatformInfo();
|
|
57
57
|
}, 5e3);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
// src/
|
|
61
|
-
import browser2 from "
|
|
62
|
-
import { MatchPattern } from "
|
|
60
|
+
// src/virtual/utils/reload-content-scripts.ts
|
|
61
|
+
import { browser as browser2 } from "wxt/browser";
|
|
62
|
+
import { MatchPattern } from "wxt/sandbox";
|
|
63
63
|
function reloadContentScript(contentScript) {
|
|
64
64
|
const manifest = browser2.runtime.getManifest();
|
|
65
65
|
if (manifest.manifest_version == 2) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/virtual/content-script-isolated-world-entrypoint.ts
|
|
2
2
|
import definition from "virtual:user-content-script-isolated-world";
|
|
3
3
|
|
|
4
|
-
// src/
|
|
4
|
+
// src/sandbox/utils/logger.ts
|
|
5
5
|
function print(method, ...args) {
|
|
6
6
|
if (import.meta.env.MODE === "production")
|
|
7
7
|
return;
|
|
@@ -19,221 +19,8 @@ var logger = {
|
|
|
19
19
|
error: (...args) => print(console.error, ...args)
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
// src/browser.ts
|
|
23
|
-
import originalBrowser from "webextension-polyfill";
|
|
24
|
-
var browser = originalBrowser;
|
|
25
|
-
|
|
26
|
-
// src/client/content-scripts/custom-events.ts
|
|
27
|
-
var WxtLocationChangeEvent = class _WxtLocationChangeEvent extends Event {
|
|
28
|
-
constructor(newUrl, oldUrl) {
|
|
29
|
-
super(_WxtLocationChangeEvent.EVENT_NAME, {});
|
|
30
|
-
this.newUrl = newUrl;
|
|
31
|
-
this.oldUrl = oldUrl;
|
|
32
|
-
}
|
|
33
|
-
static EVENT_NAME = getUniqueEventName("wxt:locationchange");
|
|
34
|
-
};
|
|
35
|
-
function getUniqueEventName(eventName) {
|
|
36
|
-
const entrypointName = typeof __ENTRYPOINT__ === "undefined" ? "build" : __ENTRYPOINT__;
|
|
37
|
-
return `${browser.runtime.id}:${entrypointName}:${eventName}`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// src/client/content-scripts/location-watcher.ts
|
|
41
|
-
function createLocationWatcher(ctx) {
|
|
42
|
-
let interval;
|
|
43
|
-
let oldUrl;
|
|
44
|
-
return {
|
|
45
|
-
/**
|
|
46
|
-
* Ensure the location watcher is actively looking for URL changes. If it's already watching,
|
|
47
|
-
* this is a noop.
|
|
48
|
-
*/
|
|
49
|
-
run() {
|
|
50
|
-
if (interval != null)
|
|
51
|
-
return;
|
|
52
|
-
oldUrl = new URL(location.href);
|
|
53
|
-
interval = ctx.setInterval(() => {
|
|
54
|
-
let newUrl = new URL(location.href);
|
|
55
|
-
if (newUrl.href !== oldUrl.href) {
|
|
56
|
-
window.dispatchEvent(new WxtLocationChangeEvent(newUrl, oldUrl));
|
|
57
|
-
oldUrl = newUrl;
|
|
58
|
-
}
|
|
59
|
-
}, 1e3);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// src/client/content-scripts/content-script-context.ts
|
|
65
|
-
var ContentScriptContext = class _ContentScriptContext {
|
|
66
|
-
constructor(contentScriptName, options) {
|
|
67
|
-
this.contentScriptName = contentScriptName;
|
|
68
|
-
this.options = options;
|
|
69
|
-
this.#abortController = new AbortController();
|
|
70
|
-
if (this.#isTopFrame) {
|
|
71
|
-
this.#stopOldScripts();
|
|
72
|
-
}
|
|
73
|
-
this.setTimeout(() => {
|
|
74
|
-
this.#listenForNewerScripts();
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
static SCRIPT_STARTED_MESSAGE_TYPE = "wxt:content-script-started";
|
|
78
|
-
#isTopFrame = window.self === window.top;
|
|
79
|
-
#abortController;
|
|
80
|
-
#locationWatcher = createLocationWatcher(this);
|
|
81
|
-
get signal() {
|
|
82
|
-
return this.#abortController.signal;
|
|
83
|
-
}
|
|
84
|
-
abort(reason) {
|
|
85
|
-
return this.#abortController.abort(reason);
|
|
86
|
-
}
|
|
87
|
-
get isInvalid() {
|
|
88
|
-
if (browser.runtime.id == null) {
|
|
89
|
-
this.notifyInvalidated();
|
|
90
|
-
}
|
|
91
|
-
return this.signal.aborted;
|
|
92
|
-
}
|
|
93
|
-
get isValid() {
|
|
94
|
-
return !this.isInvalid;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Add a listener that is called when the content script's context is invalidated.
|
|
98
|
-
*
|
|
99
|
-
* @returns A function to remove the listener.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* browser.runtime.onMessage.addListener(cb);
|
|
103
|
-
* const removeInvalidatedListener = ctx.onInvalidated(() => {
|
|
104
|
-
* browser.runtime.onMessage.removeListener(cb);
|
|
105
|
-
* })
|
|
106
|
-
* // ...
|
|
107
|
-
* removeInvalidatedListener();
|
|
108
|
-
*/
|
|
109
|
-
onInvalidated(cb) {
|
|
110
|
-
this.signal.addEventListener("abort", cb);
|
|
111
|
-
return () => this.signal.removeEventListener("abort", cb);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Return a promise that never resolves. Useful if you have an async function that shouldn't run
|
|
115
|
-
* after the context is expired.
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* const getValueFromStorage = async () => {
|
|
119
|
-
* if (ctx.isInvalid) return ctx.block();
|
|
120
|
-
*
|
|
121
|
-
* // ...
|
|
122
|
-
* }
|
|
123
|
-
*/
|
|
124
|
-
block() {
|
|
125
|
-
return new Promise(() => {
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Wrapper around `window.setInterval` that automatically clears the interval when invalidated.
|
|
130
|
-
*/
|
|
131
|
-
setInterval(handler, timeout) {
|
|
132
|
-
const id = setInterval(() => {
|
|
133
|
-
if (this.isValid)
|
|
134
|
-
handler();
|
|
135
|
-
}, timeout);
|
|
136
|
-
this.onInvalidated(() => clearInterval(id));
|
|
137
|
-
return id;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Wrapper around `window.setTimeout` that automatically clears the interval when invalidated.
|
|
141
|
-
*/
|
|
142
|
-
setTimeout(handler, timeout) {
|
|
143
|
-
const id = setTimeout(() => {
|
|
144
|
-
if (this.isValid)
|
|
145
|
-
handler();
|
|
146
|
-
}, timeout);
|
|
147
|
-
this.onInvalidated(() => clearTimeout(id));
|
|
148
|
-
return id;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Wrapper around `window.requestAnimationFrame` that automatically cancels the request when
|
|
152
|
-
* invalidated.
|
|
153
|
-
*/
|
|
154
|
-
requestAnimationFrame(callback) {
|
|
155
|
-
const id = requestAnimationFrame((...args) => {
|
|
156
|
-
if (this.isValid)
|
|
157
|
-
callback(...args);
|
|
158
|
-
});
|
|
159
|
-
this.onInvalidated(() => cancelAnimationFrame(id));
|
|
160
|
-
return id;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Wrapper around `window.requestIdleCallback` that automatically cancels the request when
|
|
164
|
-
* invalidated.
|
|
165
|
-
*/
|
|
166
|
-
requestIdleCallback(callback, options) {
|
|
167
|
-
const id = requestIdleCallback((...args) => {
|
|
168
|
-
if (!this.signal.aborted)
|
|
169
|
-
callback(...args);
|
|
170
|
-
}, options);
|
|
171
|
-
this.onInvalidated(() => cancelIdleCallback(id));
|
|
172
|
-
return id;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Call `target.addEventListener` and remove the event listener when the context is invalidated.
|
|
176
|
-
*
|
|
177
|
-
* Includes additional events useful for content scripts:
|
|
178
|
-
*
|
|
179
|
-
* - `"wxt:locationchange"` - Triggered when HTML5 history mode is used to change URL. Content
|
|
180
|
-
* scripts are not reloaded when navigating this way, so this can be used to reset the content
|
|
181
|
-
* script state on URL change, or run custom code.
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ctx.addEventListener(document, "visibilitychange", () => {
|
|
185
|
-
* // ...
|
|
186
|
-
* });
|
|
187
|
-
* ctx.addEventListener(document, "wxt:locationchange", () => {
|
|
188
|
-
* // ...
|
|
189
|
-
* });
|
|
190
|
-
*/
|
|
191
|
-
addEventListener(target, type, handler, options) {
|
|
192
|
-
if (type === "wxt:locationchange") {
|
|
193
|
-
if (this.isValid)
|
|
194
|
-
this.#locationWatcher.run();
|
|
195
|
-
}
|
|
196
|
-
target.addEventListener?.(
|
|
197
|
-
type.startsWith("wxt:") ? getUniqueEventName(type) : type,
|
|
198
|
-
// @ts-expect-error: Event don't match, but that's OK, EventTarget doesn't allow custom types in the callback
|
|
199
|
-
handler,
|
|
200
|
-
{
|
|
201
|
-
...options,
|
|
202
|
-
signal: this.signal
|
|
203
|
-
}
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* @internal
|
|
208
|
-
* Abort the abort controller and execute all `onInvalidated` listeners.
|
|
209
|
-
*/
|
|
210
|
-
notifyInvalidated() {
|
|
211
|
-
this.abort("Content script context invalidated");
|
|
212
|
-
logger.debug(
|
|
213
|
-
`Content script "${this.contentScriptName}" context invalidated`
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
#stopOldScripts() {
|
|
217
|
-
window.postMessage(
|
|
218
|
-
{
|
|
219
|
-
event: _ContentScriptContext.SCRIPT_STARTED_MESSAGE_TYPE,
|
|
220
|
-
contentScriptName: this.contentScriptName
|
|
221
|
-
},
|
|
222
|
-
"*"
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
#listenForNewerScripts() {
|
|
226
|
-
const cb = (event) => {
|
|
227
|
-
if (event.data?.type === _ContentScriptContext.SCRIPT_STARTED_MESSAGE_TYPE && event.data?.contentScriptName === this.contentScriptName) {
|
|
228
|
-
this.notifyInvalidated();
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
addEventListener("message", cb);
|
|
232
|
-
this.onInvalidated(() => removeEventListener("message", cb));
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
|
|
236
22
|
// src/virtual/content-script-isolated-world-entrypoint.ts
|
|
23
|
+
import { ContentScriptContext } from "wxt/client";
|
|
237
24
|
(async () => {
|
|
238
25
|
try {
|
|
239
26
|
const { main, ...options } = definition;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/virtual/content-script-main-world-entrypoint.ts
|
|
2
2
|
import definition from "virtual:user-content-script-main-world";
|
|
3
3
|
|
|
4
|
-
// src/
|
|
4
|
+
// src/sandbox/utils/logger.ts
|
|
5
5
|
function print(method, ...args) {
|
|
6
6
|
if (import.meta.env.MODE === "production")
|
|
7
7
|
return;
|
|
@@ -1,146 +1,6 @@
|
|
|
1
|
-
// src/testing/fake-browser.ts
|
|
2
|
-
import { fakeBrowser } from "@webext-core/fake-browser";
|
|
3
|
-
|
|
4
|
-
// src/core/utils/paths.ts
|
|
5
|
-
import normalize from "normalize-path";
|
|
6
|
-
var CSS_EXTENSIONS = ["css", "scss", "sass", "less", "styl", "stylus"];
|
|
7
|
-
var CSS_EXTENSIONS_PATTERN = `+(${CSS_EXTENSIONS.join("|")})`;
|
|
8
|
-
|
|
9
|
-
// src/core/builders/vite/plugins/devHtmlPrerender.ts
|
|
10
|
-
import { parseHTML } from "linkedom";
|
|
11
|
-
|
|
12
|
-
// src/core/builders/vite/plugins/multipageMove.ts
|
|
13
|
-
import fs, { ensureDir } from "fs-extra";
|
|
14
|
-
|
|
15
|
-
// src/core/builders/vite/plugins/unimport.ts
|
|
16
|
-
import { createUnimport } from "unimport";
|
|
17
|
-
|
|
18
|
-
// src/core/utils/unimport.ts
|
|
19
|
-
import { defu } from "defu";
|
|
20
|
-
|
|
21
|
-
// src/core/builders/vite/plugins/virtualEntrypoint.ts
|
|
22
|
-
import fs2 from "fs-extra";
|
|
23
|
-
|
|
24
|
-
// src/core/utils/constants.ts
|
|
25
|
-
var VIRTUAL_NOOP_BACKGROUND_MODULE_ID = "virtual:user-background";
|
|
26
|
-
|
|
27
|
-
// src/core/builders/vite/plugins/bundleAnalysis.ts
|
|
28
|
-
import { visualizer } from "rollup-plugin-visualizer";
|
|
29
|
-
|
|
30
|
-
// src/core/utils/fs.ts
|
|
31
|
-
import fs3 from "fs-extra";
|
|
32
|
-
import glob from "fast-glob";
|
|
33
|
-
|
|
34
|
-
// src/core/utils/building/build-entrypoints.ts
|
|
35
|
-
import fs4 from "fs-extra";
|
|
36
|
-
import pc from "picocolors";
|
|
37
|
-
|
|
38
|
-
// src/core/utils/building/find-entrypoints.ts
|
|
39
|
-
import fs5 from "fs-extra";
|
|
40
|
-
import { minimatch } from "minimatch";
|
|
41
|
-
import { parseHTML as parseHTML2 } from "linkedom";
|
|
42
|
-
import JSON5 from "json5";
|
|
43
|
-
import glob2 from "fast-glob";
|
|
44
|
-
var PATH_GLOB_TO_TYPE_MAP = {
|
|
45
|
-
"sandbox.html": "sandbox",
|
|
46
|
-
"sandbox/index.html": "sandbox",
|
|
47
|
-
"*.sandbox.html": "sandbox",
|
|
48
|
-
"*.sandbox/index.html": "sandbox",
|
|
49
|
-
"bookmarks.html": "bookmarks",
|
|
50
|
-
"bookmarks/index.html": "bookmarks",
|
|
51
|
-
"history.html": "history",
|
|
52
|
-
"history/index.html": "history",
|
|
53
|
-
"newtab.html": "newtab",
|
|
54
|
-
"newtab/index.html": "newtab",
|
|
55
|
-
"sidepanel.html": "sidepanel",
|
|
56
|
-
"sidepanel/index.html": "sidepanel",
|
|
57
|
-
"*.sidepanel.html": "sidepanel",
|
|
58
|
-
"*.sidepanel/index.html": "sidepanel",
|
|
59
|
-
"devtools.html": "devtools",
|
|
60
|
-
"devtools/index.html": "devtools",
|
|
61
|
-
"background.[jt]s": "background",
|
|
62
|
-
"background/index.[jt]s": "background",
|
|
63
|
-
[VIRTUAL_NOOP_BACKGROUND_MODULE_ID]: "background",
|
|
64
|
-
"content.[jt]s?(x)": "content-script",
|
|
65
|
-
"content/index.[jt]s?(x)": "content-script",
|
|
66
|
-
"*.content.[jt]s?(x)": "content-script",
|
|
67
|
-
"*.content/index.[jt]s?(x)": "content-script",
|
|
68
|
-
[`content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
69
|
-
[`*.content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
70
|
-
[`content/index.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
71
|
-
[`*.content/index.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
72
|
-
"popup.html": "popup",
|
|
73
|
-
"popup/index.html": "popup",
|
|
74
|
-
"options.html": "options",
|
|
75
|
-
"options/index.html": "options",
|
|
76
|
-
"*.html": "unlisted-page",
|
|
77
|
-
"*/index.html": "unlisted-page",
|
|
78
|
-
"*.[jt]s?(x)": "unlisted-script",
|
|
79
|
-
"*/index.[jt]s?(x)": "unlisted-script",
|
|
80
|
-
[`*.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style",
|
|
81
|
-
[`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
// src/core/utils/building/generate-wxt-dir.ts
|
|
85
|
-
import { createUnimport as createUnimport2 } from "unimport";
|
|
86
|
-
import fs6 from "fs-extra";
|
|
87
|
-
|
|
88
|
-
// src/core/utils/building/get-internal-config.ts
|
|
89
|
-
import { loadConfig } from "c12";
|
|
90
|
-
|
|
91
|
-
// src/core/utils/cache.ts
|
|
92
|
-
import fs7, { ensureDir as ensureDir2 } from "fs-extra";
|
|
93
|
-
|
|
94
|
-
// src/core/utils/building/get-internal-config.ts
|
|
95
|
-
import consola, { LogLevels } from "consola";
|
|
96
|
-
import defu2 from "defu";
|
|
97
|
-
|
|
98
|
-
// src/core/utils/building/import-entrypoint.ts
|
|
99
|
-
import createJITI from "jiti";
|
|
100
|
-
import { createUnimport as createUnimport3 } from "unimport";
|
|
101
|
-
import fs8 from "fs-extra";
|
|
102
|
-
import { transformSync } from "esbuild";
|
|
103
|
-
|
|
104
|
-
// src/core/utils/building/internal-build.ts
|
|
105
|
-
import pc4 from "picocolors";
|
|
106
|
-
import fs12 from "fs-extra";
|
|
107
|
-
|
|
108
|
-
// src/core/utils/log/printFileList.ts
|
|
109
|
-
import pc2 from "picocolors";
|
|
110
|
-
import fs9 from "fs-extra";
|
|
111
|
-
import { filesize } from "filesize";
|
|
112
|
-
var DEFAULT_COLOR = pc2.blue;
|
|
113
|
-
var CHUNK_COLORS = {
|
|
114
|
-
".js.map": pc2.gray,
|
|
115
|
-
".cjs.map": pc2.gray,
|
|
116
|
-
".mjs.map": pc2.gray,
|
|
117
|
-
".html": pc2.green,
|
|
118
|
-
".css": pc2.magenta,
|
|
119
|
-
".js": pc2.cyan,
|
|
120
|
-
".cjs": pc2.cyan,
|
|
121
|
-
".mjs": pc2.cyan,
|
|
122
|
-
".zip": pc2.yellow
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// src/core/utils/log/printHeader.ts
|
|
126
|
-
import pc3 from "picocolors";
|
|
127
|
-
import { consola as consola2 } from "consola";
|
|
128
|
-
|
|
129
|
-
// src/core/utils/building/internal-build.ts
|
|
130
|
-
import glob3 from "fast-glob";
|
|
131
|
-
|
|
132
|
-
// src/core/utils/manifest.ts
|
|
133
|
-
import fs11 from "fs-extra";
|
|
134
|
-
|
|
135
|
-
// src/core/utils/package.ts
|
|
136
|
-
import fs10 from "fs-extra";
|
|
137
|
-
|
|
138
|
-
// src/core/utils/manifest.ts
|
|
139
|
-
import { produce } from "immer";
|
|
140
|
-
import defu3 from "defu";
|
|
141
|
-
|
|
142
1
|
// src/virtual/mock-browser.ts
|
|
143
|
-
|
|
2
|
+
import { fakeBrowser as mockBrowser } from "wxt/testing";
|
|
3
|
+
var mock_browser_default = mockBrowser;
|
|
144
4
|
export {
|
|
145
5
|
mock_browser_default as default
|
|
146
6
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/sandbox/utils/logger.ts
|
|
2
2
|
function print(method, ...args) {
|
|
3
3
|
if (import.meta.env.MODE === "production")
|
|
4
4
|
return;
|
|
@@ -16,7 +16,7 @@ var logger = {
|
|
|
16
16
|
error: (...args) => print(console.error, ...args)
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
// src/
|
|
19
|
+
// src/virtual/utils/setup-web-socket.ts
|
|
20
20
|
function setupWebSocket(onMessage) {
|
|
21
21
|
const serverUrl = `${__DEV_SERVER_PROTOCOL__}//${__DEV_SERVER_HOSTNAME__}:${__DEV_SERVER_PORT__}`;
|
|
22
22
|
logger.debug("Connecting to dev server @", serverUrl);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.12.
|
|
4
|
+
"version": "0.12.2-alpha2",
|
|
5
5
|
"description": "Next gen framework for developing web extensions",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=18",
|
|
@@ -161,7 +161,9 @@
|
|
|
161
161
|
"lint": "run-p -c -s lint:*",
|
|
162
162
|
"lint:eslint": "echo 'ESLint: TODO'",
|
|
163
163
|
"lint:package": "publint",
|
|
164
|
-
"compile": "
|
|
164
|
+
"compile": "run-s -c compile:*",
|
|
165
|
+
"compile:wxt": "tsc --noEmit",
|
|
166
|
+
"compile:virtual": "tsc --noEmit",
|
|
165
167
|
"test": "vitest",
|
|
166
168
|
"test:coverage": "vitest run --coverage",
|
|
167
169
|
"prepublish": "pnpm -s build",
|