@libo11y/webext 0.2.1 → 0.4.0
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/README.md +2 -1
- package/dist/content.d.ts +6 -2
- package/dist/content.js +24 -8
- package/dist/internal.d.ts +7 -0
- package/dist/internal.js +6 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worker.js +9 -2
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -10,7 +10,8 @@ contexts never post to the collector. They forward their batches to the
|
|
|
10
10
|
worker by runtime messaging. Trace context crosses with every traced
|
|
11
11
|
message, and consent is one state for the whole extension.
|
|
12
12
|
|
|
13
|
-
It has no RUM features. Those belong to `@libo11y/rum
|
|
13
|
+
It has no RUM features. Those belong to `@libo11y/rum`, whose
|
|
14
|
+
`@libo11y/rum/webext` entry point builds on this package.
|
|
14
15
|
|
|
15
16
|
```sh
|
|
16
17
|
npm install @libo11y/webext
|
package/dist/content.d.ts
CHANGED
|
@@ -51,5 +51,9 @@ export declare function defaultContentDeps(): ContentDeps;
|
|
|
51
51
|
* worker stores "denied", and this context revokes, clearing its buffers.
|
|
52
52
|
*/
|
|
53
53
|
export declare function setupContentScript(options?: ContentScriptSetupOptions): Promise<ContentScriptTelemetry>;
|
|
54
|
-
/**
|
|
55
|
-
|
|
54
|
+
/**
|
|
55
|
+
* setupContentScript over deps. Internal: the seam the unit tests and @libo11y/rum use. With install
|
|
56
|
+
* false it builds the telemetry as web's createTelemetry does: no globals, no instrumentation and
|
|
57
|
+
* no active consent, still flushing on hide (tests that run two contexts in one process).
|
|
58
|
+
*/
|
|
59
|
+
export declare function setupContentScriptWith(options: ContentScriptSetupOptions, deps: ContentDeps, install?: boolean): Promise<ContentScriptTelemetry>;
|
package/dist/content.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WP5 (webext). setupContentScript for content scripts and extension pages.
|
|
3
3
|
*/
|
|
4
|
-
import { setupWith } from "@libo11y/core";
|
|
4
|
+
import { createTelemetryWith, setupWith, } from "@libo11y/core";
|
|
5
5
|
import { installXhrInstrumentation, recordDocumentLoad, } from "@libo11y/web";
|
|
6
6
|
import { activeConsent, createConsentController, createDelivery, createMemoryQueue, installFetchInstrumentation, installFlushOnHide, setActiveConsent, webPlatform, } from "@libo11y/web/internal";
|
|
7
|
+
import { flushInBackground } from "@libo11y/web/portable";
|
|
7
8
|
import { diag } from "@opentelemetry/api";
|
|
8
9
|
import { getChrome } from "./chrome.js";
|
|
9
10
|
import { readStoredConsent, syncConsent } from "./consent-sync.js";
|
|
@@ -65,8 +66,12 @@ async function cleanup(steps) {
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
|
-
/**
|
|
69
|
-
|
|
69
|
+
/**
|
|
70
|
+
* setupContentScript over deps. Internal: the seam the unit tests and @libo11y/rum use. With install
|
|
71
|
+
* false it builds the telemetry as web's createTelemetry does: no globals, no instrumentation and
|
|
72
|
+
* no active consent, still flushing on hide (tests that run two contexts in one process).
|
|
73
|
+
*/
|
|
74
|
+
export async function setupContentScriptWith(options, deps, install = true) {
|
|
70
75
|
const chrome = deps.chrome;
|
|
71
76
|
if (chrome === undefined) {
|
|
72
77
|
throw new Error("o11y: setupContentScript needs the extension API (chrome.runtime)");
|
|
@@ -106,7 +111,9 @@ export async function setupContentScriptWith(options, deps) {
|
|
|
106
111
|
...(options.contextManager === undefined ? {} : { contextManager: options.contextManager }),
|
|
107
112
|
});
|
|
108
113
|
const coreOptions = { ...options, console: options.console ?? false };
|
|
109
|
-
telemetry =
|
|
114
|
+
telemetry = install
|
|
115
|
+
? await setupWith(coreOptions, platform)
|
|
116
|
+
: await createTelemetryWith(coreOptions, platform);
|
|
110
117
|
}
|
|
111
118
|
catch (err) {
|
|
112
119
|
await cleanup(steps);
|
|
@@ -115,10 +122,17 @@ export async function setupContentScriptWith(options, deps) {
|
|
|
115
122
|
const core = telemetry;
|
|
116
123
|
const doc = deps.document;
|
|
117
124
|
if (doc !== undefined)
|
|
118
|
-
steps.unshift(deps.installFlushOnHide(doc, deps.window, () => core
|
|
119
|
-
steps.unshift(
|
|
120
|
-
|
|
121
|
-
|
|
125
|
+
steps.unshift(deps.installFlushOnHide(doc, deps.window, () => flushInBackground(core, "flush on hide")));
|
|
126
|
+
steps.unshift(
|
|
127
|
+
// The queue is emptied first, whatever the flush does, as on a page.
|
|
128
|
+
controller.onRevoke(async () => {
|
|
129
|
+
const cleared = delivery.clear();
|
|
130
|
+
try {
|
|
131
|
+
await core.forceFlush();
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
await cleared;
|
|
135
|
+
}
|
|
122
136
|
}));
|
|
123
137
|
const messaging = createTracedMessaging(chrome, core.propagator);
|
|
124
138
|
const uninstalls = [];
|
|
@@ -143,6 +157,8 @@ export async function setupContentScriptWith(options, deps) {
|
|
|
143
157
|
})();
|
|
144
158
|
return shutdownPromise;
|
|
145
159
|
};
|
|
160
|
+
if (!install)
|
|
161
|
+
return handle;
|
|
146
162
|
try {
|
|
147
163
|
setActiveConsent(controller.consent);
|
|
148
164
|
const instr = options.instrumentations ?? {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @libo11y/webext/internal: the seams @libo11y/rum composes. For libo11y packages only; it follows
|
|
3
|
+
* the package version but carries no compatibility promise and has no API report.
|
|
4
|
+
*/
|
|
5
|
+
export type { ChromeLike } from "./chrome.ts";
|
|
6
|
+
export { type ContentDeps, defaultContentDeps, setupContentScriptWith, WORKER_ENDPOINT } from "./content.ts";
|
|
7
|
+
export { defaultWorkerDeps, setupWorkerWith, type WorkerDeps } from "./worker.ts";
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @libo11y/webext/internal: the seams @libo11y/rum composes. For libo11y packages only; it follows
|
|
3
|
+
* the package version but carries no compatibility promise and has no API report.
|
|
4
|
+
*/
|
|
5
|
+
export { defaultContentDeps, setupContentScriptWith, WORKER_ENDPOINT } from "./content.js";
|
|
6
|
+
export { defaultWorkerDeps, setupWorkerWith } from "./worker.js";
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The @libo11y/webext package version. scripts/release.ts keeps it equal to package.json. */
|
|
2
|
-
export declare const VERSION = "0.
|
|
2
|
+
export declare const VERSION = "0.4.0";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The @libo11y/webext package version. scripts/release.ts keeps it equal to package.json. */
|
|
2
|
-
export const VERSION = "0.
|
|
2
|
+
export const VERSION = "0.4.0";
|
package/dist/worker.js
CHANGED
|
@@ -283,9 +283,16 @@ export async function setupWorkerWith(options, deps) {
|
|
|
283
283
|
}
|
|
284
284
|
const { controller, queue, delivery, endpoints } = built;
|
|
285
285
|
const telemetry = core;
|
|
286
|
+
// The queue is emptied first, whatever the flush does: a flush waits for exports in flight, up to
|
|
287
|
+
// its deadline, and a worker stopped in that time would otherwise keep the queue for a later grant.
|
|
286
288
|
const unregisterRevoke = controller.onRevoke(async () => {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
+
const cleared = delivery.clear();
|
|
290
|
+
try {
|
|
291
|
+
await telemetry.forceFlush();
|
|
292
|
+
}
|
|
293
|
+
finally {
|
|
294
|
+
await cleared;
|
|
295
|
+
}
|
|
289
296
|
});
|
|
290
297
|
const messaging = createTracedMessaging(chrome, telemetry.propagator);
|
|
291
298
|
const uninstalls = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libo11y/webext",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "The libo11y Manifest V3 extension platform for TypeScript: setup for the service worker with a queue persisted to IndexedDB on every batch, setup for content scripts and extension pages that forward their records to the worker by runtime messaging, and trace context that crosses with every message.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./internal": {
|
|
14
|
+
"types": "./dist/internal.d.ts",
|
|
15
|
+
"default": "./dist/internal.js"
|
|
12
16
|
}
|
|
13
17
|
},
|
|
14
18
|
"repository": {
|
|
@@ -17,16 +21,16 @@
|
|
|
17
21
|
"directory": "ts/packages/webext"
|
|
18
22
|
},
|
|
19
23
|
"dependencies": {
|
|
20
|
-
"@libo11y/core": "0.
|
|
21
|
-
"@libo11y/spec": "0.
|
|
22
|
-
"@libo11y/web": "0.
|
|
24
|
+
"@libo11y/core": "0.4.0",
|
|
25
|
+
"@libo11y/spec": "0.4.0",
|
|
26
|
+
"@libo11y/web": "0.4.0",
|
|
23
27
|
"@opentelemetry/api": "1.10.0",
|
|
24
28
|
"@opentelemetry/sdk-logs": "3.1.1",
|
|
25
29
|
"@opentelemetry/sdk-metrics": "3.1.1",
|
|
26
30
|
"@opentelemetry/sdk-trace": "3.1.1"
|
|
27
31
|
},
|
|
28
32
|
"devDependencies": {
|
|
29
|
-
"@libo11y/test": "0.
|
|
33
|
+
"@libo11y/test": "0.4.0",
|
|
30
34
|
"fake-indexeddb": "6.2.7"
|
|
31
35
|
},
|
|
32
36
|
"files": [
|