wxt 0.19.12 → 0.19.13
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/client/content-scripts/content-script-context.d.ts +7 -1
- package/dist/client/content-scripts/content-script-context.mjs +13 -13
- package/dist/core/resolve-config.mjs +1 -1
- package/dist/core/utils/env.d.ts +3 -2
- package/dist/core/utils/env.mjs +12 -2
- package/dist/version.mjs +1 -1
- package/package.json +1 -1
|
@@ -31,10 +31,12 @@ import { WxtLocationChangeEvent } from './custom-events';
|
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
export declare class ContentScriptContext implements AbortController {
|
|
34
|
-
#private;
|
|
35
34
|
private readonly contentScriptName;
|
|
36
35
|
readonly options?: Omit<ContentScriptDefinition, "main"> | undefined;
|
|
37
36
|
private static SCRIPT_STARTED_MESSAGE_TYPE;
|
|
37
|
+
private isTopFrame;
|
|
38
|
+
private abortController;
|
|
39
|
+
private locationWatcher;
|
|
38
40
|
constructor(contentScriptName: string, options?: Omit<ContentScriptDefinition, "main"> | undefined);
|
|
39
41
|
get signal(): AbortSignal;
|
|
40
42
|
abort(reason?: any): void;
|
|
@@ -107,6 +109,10 @@ export declare class ContentScriptContext implements AbortController {
|
|
|
107
109
|
* Abort the abort controller and execute all `onInvalidated` listeners.
|
|
108
110
|
*/
|
|
109
111
|
notifyInvalidated(): void;
|
|
112
|
+
stopOldScripts(): void;
|
|
113
|
+
listenForNewerScripts(options?: {
|
|
114
|
+
ignoreFirstEvent?: boolean;
|
|
115
|
+
}): void;
|
|
110
116
|
}
|
|
111
117
|
interface WxtContentScriptEventMap extends WindowEventMap {
|
|
112
118
|
'wxt:locationchange': WxtLocationChangeEvent;
|
|
@@ -6,23 +6,23 @@ export class ContentScriptContext {
|
|
|
6
6
|
constructor(contentScriptName, options) {
|
|
7
7
|
this.contentScriptName = contentScriptName;
|
|
8
8
|
this.options = options;
|
|
9
|
-
this
|
|
10
|
-
if (this
|
|
11
|
-
this
|
|
12
|
-
this
|
|
9
|
+
this.abortController = new AbortController();
|
|
10
|
+
if (this.isTopFrame) {
|
|
11
|
+
this.listenForNewerScripts({ ignoreFirstEvent: true });
|
|
12
|
+
this.stopOldScripts();
|
|
13
13
|
} else {
|
|
14
|
-
this
|
|
14
|
+
this.listenForNewerScripts();
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
static SCRIPT_STARTED_MESSAGE_TYPE = "wxt:content-script-started";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
isTopFrame = window.self === window.top;
|
|
19
|
+
abortController;
|
|
20
|
+
locationWatcher = createLocationWatcher(this);
|
|
21
21
|
get signal() {
|
|
22
|
-
return this
|
|
22
|
+
return this.abortController.signal;
|
|
23
23
|
}
|
|
24
24
|
abort(reason) {
|
|
25
|
-
return this
|
|
25
|
+
return this.abortController.abort(reason);
|
|
26
26
|
}
|
|
27
27
|
get isInvalid() {
|
|
28
28
|
if (browser.runtime.id == null) {
|
|
@@ -126,7 +126,7 @@ export class ContentScriptContext {
|
|
|
126
126
|
*/
|
|
127
127
|
addEventListener(target, type, handler, options) {
|
|
128
128
|
if (type === "wxt:locationchange") {
|
|
129
|
-
if (this.isValid) this
|
|
129
|
+
if (this.isValid) this.locationWatcher.run();
|
|
130
130
|
}
|
|
131
131
|
target.addEventListener?.(
|
|
132
132
|
type.startsWith("wxt:") ? getUniqueEventName(type) : type,
|
|
@@ -148,7 +148,7 @@ export class ContentScriptContext {
|
|
|
148
148
|
`Content script "${this.contentScriptName}" context invalidated`
|
|
149
149
|
);
|
|
150
150
|
}
|
|
151
|
-
|
|
151
|
+
stopOldScripts() {
|
|
152
152
|
window.postMessage(
|
|
153
153
|
{
|
|
154
154
|
type: ContentScriptContext.SCRIPT_STARTED_MESSAGE_TYPE,
|
|
@@ -157,7 +157,7 @@ export class ContentScriptContext {
|
|
|
157
157
|
"*"
|
|
158
158
|
);
|
|
159
159
|
}
|
|
160
|
-
|
|
160
|
+
listenForNewerScripts(options) {
|
|
161
161
|
let isFirst = true;
|
|
162
162
|
const cb = (event) => {
|
|
163
163
|
if (event.data?.type === ContentScriptContext.SCRIPT_STARTED_MESSAGE_TYPE && event.data?.contentScriptName === this.contentScriptName) {
|
|
@@ -34,7 +34,7 @@ export async function resolveConfig(inlineConfig, command) {
|
|
|
34
34
|
const manifestVersion = mergedConfig.manifestVersion ?? (browser === "firefox" || browser === "safari" ? 2 : 3);
|
|
35
35
|
const mode = mergedConfig.mode ?? COMMAND_MODES[command];
|
|
36
36
|
const env = { browser, command, manifestVersion, mode };
|
|
37
|
-
loadEnv(mode);
|
|
37
|
+
loadEnv(mode, browser);
|
|
38
38
|
const root = path.resolve(
|
|
39
39
|
inlineConfig.root ?? userConfig.root ?? process.cwd()
|
|
40
40
|
);
|
package/dist/core/utils/env.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { TargetBrowser } from '../../types';
|
|
1
2
|
/**
|
|
2
|
-
* Load environment files based on the current mode.
|
|
3
|
+
* Load environment files based on the current mode and browser.
|
|
3
4
|
*/
|
|
4
|
-
export declare function loadEnv(mode: string): import("dotenv").DotenvConfigOutput;
|
|
5
|
+
export declare function loadEnv(mode: string, browser: TargetBrowser): import("dotenv").DotenvConfigOutput;
|
package/dist/core/utils/env.mjs
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { config } from "dotenv";
|
|
2
|
-
export function loadEnv(mode) {
|
|
2
|
+
export function loadEnv(mode, browser) {
|
|
3
3
|
return config({
|
|
4
|
-
|
|
4
|
+
// Files on top override files below
|
|
5
|
+
path: [
|
|
6
|
+
`.env.${mode}.${browser}.local`,
|
|
7
|
+
`.env.${mode}.${browser}`,
|
|
8
|
+
`.env.${browser}.local`,
|
|
9
|
+
`.env.${browser}`,
|
|
10
|
+
`.env.${mode}.local`,
|
|
11
|
+
`.env.${mode}`,
|
|
12
|
+
`.env.local`,
|
|
13
|
+
`.env`
|
|
14
|
+
]
|
|
5
15
|
});
|
|
6
16
|
}
|
package/dist/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.19.
|
|
1
|
+
export const version = "0.19.13";
|