@ricsam/isolate 0.1.12 → 0.1.14
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 +15 -0
- package/dist/cjs/bridge/legacy-adapters.cjs +3 -2
- package/dist/cjs/bridge/legacy-adapters.cjs.map +3 -3
- package/dist/cjs/bridge/runtime-bindings.cjs +9 -7
- package/dist/cjs/bridge/runtime-bindings.cjs.map +3 -3
- package/dist/cjs/bridge/sandbox-isolate.cjs +58 -2
- package/dist/cjs/bridge/sandbox-isolate.cjs.map +3 -3
- package/dist/cjs/host/create-isolate-host.cjs +7 -2
- package/dist/cjs/host/create-isolate-host.cjs.map +3 -3
- package/dist/cjs/host/nested-host-controller.cjs +36 -4
- package/dist/cjs/host/nested-host-controller.cjs.map +3 -3
- package/dist/cjs/internal/client/connection.cjs +12 -10
- package/dist/cjs/internal/client/connection.cjs.map +3 -3
- package/dist/cjs/internal/console/index.cjs +18 -14
- package/dist/cjs/internal/console/index.cjs.map +3 -3
- package/dist/cjs/internal/daemon/connection.cjs +11 -12
- package/dist/cjs/internal/daemon/connection.cjs.map +3 -3
- package/dist/cjs/internal/event-callback.cjs +70 -0
- package/dist/cjs/internal/event-callback.cjs.map +10 -0
- package/dist/cjs/internal/playwright/handler.cjs +3 -4
- package/dist/cjs/internal/playwright/handler.cjs.map +3 -3
- package/dist/cjs/internal/playwright/index.cjs +58 -64
- package/dist/cjs/internal/playwright/index.cjs.map +3 -3
- package/dist/cjs/internal/protocol/types.cjs.map +2 -2
- package/dist/cjs/internal/runtime/index.cjs +8 -13
- package/dist/cjs/internal/runtime/index.cjs.map +3 -3
- package/dist/cjs/internal/test-environment/index.cjs +3 -2
- package/dist/cjs/internal/test-environment/index.cjs.map +3 -3
- package/dist/cjs/internal/typecheck/isolate-types.cjs +50 -1
- package/dist/cjs/internal/typecheck/isolate-types.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/playwright.cjs.map +2 -2
- package/dist/cjs/runtime/namespaced-runtime.cjs +4 -1
- package/dist/cjs/runtime/namespaced-runtime.cjs.map +3 -3
- package/dist/cjs/runtime/test-event-subscriptions.cjs +73 -0
- package/dist/cjs/runtime/test-event-subscriptions.cjs.map +10 -0
- package/dist/cjs/runtime/test-runtime.cjs +26 -3
- package/dist/cjs/runtime/test-runtime.cjs.map +3 -3
- package/dist/mjs/bridge/legacy-adapters.mjs +3 -2
- package/dist/mjs/bridge/legacy-adapters.mjs.map +3 -3
- package/dist/mjs/bridge/runtime-bindings.mjs +9 -7
- package/dist/mjs/bridge/runtime-bindings.mjs.map +3 -3
- package/dist/mjs/bridge/sandbox-isolate.mjs +58 -2
- package/dist/mjs/bridge/sandbox-isolate.mjs.map +3 -3
- package/dist/mjs/host/create-isolate-host.mjs +7 -2
- package/dist/mjs/host/create-isolate-host.mjs.map +3 -3
- package/dist/mjs/host/nested-host-controller.mjs +36 -4
- package/dist/mjs/host/nested-host-controller.mjs.map +3 -3
- package/dist/mjs/internal/client/connection.mjs +12 -10
- package/dist/mjs/internal/client/connection.mjs.map +3 -3
- package/dist/mjs/internal/console/index.mjs +18 -14
- package/dist/mjs/internal/console/index.mjs.map +3 -3
- package/dist/mjs/internal/daemon/connection.mjs +11 -12
- package/dist/mjs/internal/daemon/connection.mjs.map +3 -3
- package/dist/mjs/internal/event-callback.mjs +30 -0
- package/dist/mjs/internal/event-callback.mjs.map +10 -0
- package/dist/mjs/internal/playwright/handler.mjs +3 -4
- package/dist/mjs/internal/playwright/handler.mjs.map +3 -3
- package/dist/mjs/internal/playwright/index.mjs +58 -64
- package/dist/mjs/internal/playwright/index.mjs.map +3 -3
- package/dist/mjs/internal/protocol/types.mjs.map +2 -2
- package/dist/mjs/internal/runtime/index.mjs +8 -13
- package/dist/mjs/internal/runtime/index.mjs.map +3 -3
- package/dist/mjs/internal/test-environment/index.mjs +3 -2
- package/dist/mjs/internal/test-environment/index.mjs.map +3 -3
- package/dist/mjs/internal/typecheck/isolate-types.mjs +50 -1
- package/dist/mjs/internal/typecheck/isolate-types.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/playwright.mjs.map +2 -2
- package/dist/mjs/runtime/namespaced-runtime.mjs +4 -1
- package/dist/mjs/runtime/namespaced-runtime.mjs.map +3 -3
- package/dist/mjs/runtime/test-event-subscriptions.mjs +33 -0
- package/dist/mjs/runtime/test-event-subscriptions.mjs.map +10 -0
- package/dist/mjs/runtime/test-runtime.mjs +26 -3
- package/dist/mjs/runtime/test-runtime.mjs.map +3 -3
- package/dist/types/internal/console/index.d.ts +2 -1
- package/dist/types/internal/event-callback.d.ts +1 -0
- package/dist/types/internal/protocol/types.d.ts +4 -3
- package/dist/types/internal/runtime/index.d.ts +0 -6
- package/dist/types/internal/test-environment/index.d.ts +1 -1
- package/dist/types/internal/typecheck/isolate-types.d.ts +2 -2
- package/dist/types/playwright.d.ts +1 -0
- package/dist/types/runtime/namespaced-runtime.d.ts +3 -1
- package/dist/types/runtime/test-event-subscriptions.d.ts +12 -0
- package/dist/types/types.d.ts +12 -0
- package/package.json +1 -1
|
@@ -67,8 +67,12 @@ __export(exports_console, {
|
|
|
67
67
|
});
|
|
68
68
|
module.exports = __toCommonJS(exports_console);
|
|
69
69
|
var import_isolated_vm = __toESM(require("@ricsam/isolated-vm"));
|
|
70
|
+
var import_event_callback = require("../event-callback.cjs");
|
|
70
71
|
async function setupConsole(context, options) {
|
|
71
72
|
const opts = options ?? {};
|
|
73
|
+
const emitEntry = (entry) => {
|
|
74
|
+
import_event_callback.invokeBestEffortEventHandler("console.onEntry", opts.onEntry, entry);
|
|
75
|
+
};
|
|
72
76
|
const timers = new Map;
|
|
73
77
|
const counters = new Map;
|
|
74
78
|
let groupDepth = 0;
|
|
@@ -76,7 +80,7 @@ async function setupConsole(context, options) {
|
|
|
76
80
|
const logLevels = ["log", "warn", "error", "debug", "info"];
|
|
77
81
|
for (const level of logLevels) {
|
|
78
82
|
global.setSync(`__console_${level}`, new import_isolated_vm.default.Callback((stdout) => {
|
|
79
|
-
|
|
83
|
+
emitEntry({
|
|
80
84
|
type: "output",
|
|
81
85
|
level,
|
|
82
86
|
stdout,
|
|
@@ -85,21 +89,21 @@ async function setupConsole(context, options) {
|
|
|
85
89
|
}));
|
|
86
90
|
}
|
|
87
91
|
global.setSync("__console_dir", new import_isolated_vm.default.Callback((stdout) => {
|
|
88
|
-
|
|
92
|
+
emitEntry({
|
|
89
93
|
type: "dir",
|
|
90
94
|
stdout,
|
|
91
95
|
groupDepth
|
|
92
96
|
});
|
|
93
97
|
}));
|
|
94
98
|
global.setSync("__console_table", new import_isolated_vm.default.Callback((stdout) => {
|
|
95
|
-
|
|
99
|
+
emitEntry({
|
|
96
100
|
type: "table",
|
|
97
101
|
stdout,
|
|
98
102
|
groupDepth
|
|
99
103
|
});
|
|
100
104
|
}));
|
|
101
105
|
global.setSync("__console_trace", new import_isolated_vm.default.Callback((stdout, stack) => {
|
|
102
|
-
|
|
106
|
+
emitEntry({
|
|
103
107
|
type: "trace",
|
|
104
108
|
stdout,
|
|
105
109
|
stack,
|
|
@@ -116,7 +120,7 @@ async function setupConsole(context, options) {
|
|
|
116
120
|
if (start !== undefined) {
|
|
117
121
|
const duration = performance.now() - start;
|
|
118
122
|
timers.delete(l);
|
|
119
|
-
|
|
123
|
+
emitEntry({
|
|
120
124
|
type: "time",
|
|
121
125
|
label: l,
|
|
122
126
|
duration,
|
|
@@ -129,7 +133,7 @@ async function setupConsole(context, options) {
|
|
|
129
133
|
const start = timers.get(l);
|
|
130
134
|
if (start !== undefined) {
|
|
131
135
|
const actualDuration = performance.now() - start;
|
|
132
|
-
|
|
136
|
+
emitEntry({
|
|
133
137
|
type: "timeLog",
|
|
134
138
|
label: l,
|
|
135
139
|
duration: actualDuration,
|
|
@@ -142,7 +146,7 @@ async function setupConsole(context, options) {
|
|
|
142
146
|
const l = label ?? "default";
|
|
143
147
|
const count = (counters.get(l) ?? 0) + 1;
|
|
144
148
|
counters.set(l, count);
|
|
145
|
-
|
|
149
|
+
emitEntry({
|
|
146
150
|
type: "count",
|
|
147
151
|
label: l,
|
|
148
152
|
count,
|
|
@@ -152,7 +156,7 @@ async function setupConsole(context, options) {
|
|
|
152
156
|
global.setSync("__console_countReset", new import_isolated_vm.default.Callback((label) => {
|
|
153
157
|
const l = label ?? "default";
|
|
154
158
|
counters.delete(l);
|
|
155
|
-
|
|
159
|
+
emitEntry({
|
|
156
160
|
type: "countReset",
|
|
157
161
|
label: l,
|
|
158
162
|
groupDepth
|
|
@@ -160,7 +164,7 @@ async function setupConsole(context, options) {
|
|
|
160
164
|
}));
|
|
161
165
|
global.setSync("__console_group", new import_isolated_vm.default.Callback((label) => {
|
|
162
166
|
const l = label ?? "default";
|
|
163
|
-
|
|
167
|
+
emitEntry({
|
|
164
168
|
type: "group",
|
|
165
169
|
label: l,
|
|
166
170
|
collapsed: false,
|
|
@@ -170,7 +174,7 @@ async function setupConsole(context, options) {
|
|
|
170
174
|
}));
|
|
171
175
|
global.setSync("__console_groupCollapsed", new import_isolated_vm.default.Callback((label) => {
|
|
172
176
|
const l = label ?? "default";
|
|
173
|
-
|
|
177
|
+
emitEntry({
|
|
174
178
|
type: "group",
|
|
175
179
|
label: l,
|
|
176
180
|
collapsed: true,
|
|
@@ -182,16 +186,16 @@ async function setupConsole(context, options) {
|
|
|
182
186
|
if (groupDepth > 0) {
|
|
183
187
|
groupDepth--;
|
|
184
188
|
}
|
|
185
|
-
|
|
189
|
+
emitEntry({
|
|
186
190
|
type: "groupEnd",
|
|
187
191
|
groupDepth
|
|
188
192
|
});
|
|
189
193
|
}));
|
|
190
194
|
global.setSync("__console_clear", new import_isolated_vm.default.Callback(() => {
|
|
191
|
-
|
|
195
|
+
emitEntry({ type: "clear" });
|
|
192
196
|
}));
|
|
193
197
|
global.setSync("__console_assert", new import_isolated_vm.default.Callback((stdout) => {
|
|
194
|
-
|
|
198
|
+
emitEntry({
|
|
195
199
|
type: "assert",
|
|
196
200
|
stdout,
|
|
197
201
|
groupDepth
|
|
@@ -503,4 +507,4 @@ async function setupConsole(context, options) {
|
|
|
503
507
|
};
|
|
504
508
|
}
|
|
505
509
|
|
|
506
|
-
//# debugId=
|
|
510
|
+
//# debugId=9D90A82ECBFF1C6364756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/internal/console/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import ivm from \"@ricsam/isolated-vm\";\n\n/**\n * Console entry types for structured console output.\n * Each entry type captures the specific data needed to render like DevTools.\n * Output is pre-formatted as stdout strings (like Node.js console) inside the sandbox.\n */\nexport type ConsoleEntry =\n | {\n type: \"output\";\n level: \"log\" | \"warn\" | \"error\" | \"info\" | \"debug\";\n stdout: string;\n groupDepth: number;\n }\n | {\n /** Browser console output (from Playwright page, not sandbox) */\n type: \"browserOutput\";\n level: string;\n stdout: string;\n location?: {\n url?: string;\n lineNumber?: number;\n columnNumber?: number;\n };\n timestamp: number;\n }\n | { type: \"dir\"; stdout: string; groupDepth: number }\n | { type: \"table\"; stdout: string; groupDepth: number }\n | { type: \"time\"; label: string; duration: number; groupDepth: number }\n | {\n type: \"timeLog\";\n label: string;\n duration: number;\n stdout: string;\n groupDepth: number;\n }\n | { type: \"count\"; label: string; count: number; groupDepth: number }\n | { type: \"countReset\"; label: string; groupDepth: number }\n | { type: \"assert\"; stdout: string; groupDepth: number }\n | {\n type: \"group\";\n label: string;\n collapsed: boolean;\n groupDepth: number;\n }\n | { type: \"groupEnd\"; groupDepth: number }\n | { type: \"clear\" }\n | { type: \"trace\"; stdout: string; stack: string; groupDepth: number };\n\n/**\n * Console options with a single structured callback.\n */\nexport interface ConsoleOptions {\n /**\n * Callback invoked for each console operation.\n * Receives a structured entry with all data needed to render the output.\n */\n onEntry?: (entry: ConsoleEntry) => void;\n}\n\n/**\n * Console handle for accessing internal state.\n */\nexport interface ConsoleHandle {\n dispose(): void;\n reset(): void;\n getTimers(): Map<string, number>;\n getCounters(): Map<string, number>;\n getGroupDepth(): number;\n}\n\n\n/**\n * Setup console API in an isolated-vm context\n *\n * Injects console.log, console.warn, console.error, console.info, console.debug,\n * console.trace, console.dir, console.table, console.time, console.timeEnd,\n * console.timeLog, console.count, console.countReset, console.group,\n * console.groupCollapsed, console.groupEnd, console.clear, console.assert\n *\n * @example\n * const handle = await setupConsole(context, {\n * onEntry: (entry) => {\n * if (entry.type === 'output') {\n * console.log(`[${entry.level}]`, ...entry.args);\n * }\n * }\n * });\n */\nexport async function setupConsole(\n context: ivm.Context,\n options?: ConsoleOptions\n): Promise<ConsoleHandle> {\n const opts = options ?? {};\n\n // State management\n const timers = new Map<string, number>();\n const counters = new Map<string, number>();\n let groupDepth = 0;\n\n const global = context.global;\n\n // Log-level methods (output type)\n const logLevels = [\"log\", \"warn\", \"error\", \"debug\", \"info\"] as const;\n\n for (const level of logLevels) {\n global.setSync(\n `__console_${level}`,\n new ivm.Callback((stdout: string) => {\n opts.onEntry?.({\n type: \"output\",\n level,\n stdout,\n groupDepth,\n });\n })\n );\n }\n\n // dir method\n global.setSync(\n \"__console_dir\",\n new ivm.Callback((stdout: string) => {\n opts.onEntry?.({\n type: \"dir\",\n stdout,\n groupDepth,\n });\n })\n );\n\n // table method\n global.setSync(\n \"__console_table\",\n new ivm.Callback((stdout: string) => {\n opts.onEntry?.({\n type: \"table\",\n stdout,\n groupDepth,\n });\n })\n );\n\n // trace method (includes stack)\n global.setSync(\n \"__console_trace\",\n new ivm.Callback((stdout: string, stack: string) => {\n opts.onEntry?.({\n type: \"trace\",\n stdout,\n stack,\n groupDepth,\n });\n })\n );\n\n // Timing methods\n global.setSync(\n \"__console_time\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n timers.set(l, performance.now());\n })\n );\n\n global.setSync(\n \"__console_timeEnd\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n const start = timers.get(l);\n if (start !== undefined) {\n const duration = performance.now() - start;\n timers.delete(l);\n opts.onEntry?.({\n type: \"time\",\n label: l,\n duration,\n groupDepth,\n });\n }\n })\n );\n\n global.setSync(\n \"__console_timeLog\",\n new ivm.Callback((label: string, duration: number, stdout: string) => {\n const l = label ?? \"default\";\n const start = timers.get(l);\n if (start !== undefined) {\n const actualDuration = performance.now() - start;\n opts.onEntry?.({\n type: \"timeLog\",\n label: l,\n duration: actualDuration,\n stdout,\n groupDepth,\n });\n }\n })\n );\n\n // Counting methods\n global.setSync(\n \"__console_count\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n const count = (counters.get(l) ?? 0) + 1;\n counters.set(l, count);\n opts.onEntry?.({\n type: \"count\",\n label: l,\n count,\n groupDepth,\n });\n })\n );\n\n global.setSync(\n \"__console_countReset\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n counters.delete(l);\n opts.onEntry?.({\n type: \"countReset\",\n label: l,\n groupDepth,\n });\n })\n );\n\n // Grouping methods\n global.setSync(\n \"__console_group\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n opts.onEntry?.({\n type: \"group\",\n label: l,\n collapsed: false,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupCollapsed\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n opts.onEntry?.({\n type: \"group\",\n label: l,\n collapsed: true,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupEnd\",\n new ivm.Callback(() => {\n if (groupDepth > 0) {\n groupDepth--;\n }\n opts.onEntry?.({\n type: \"groupEnd\",\n groupDepth,\n });\n })\n );\n\n // Other methods\n global.setSync(\n \"__console_clear\",\n new ivm.Callback(() => {\n opts.onEntry?.({ type: \"clear\" });\n })\n );\n\n global.setSync(\n \"__console_assert\",\n new ivm.Callback((stdout: string) => {\n opts.onEntry?.({\n type: \"assert\",\n stdout,\n groupDepth,\n });\n })\n );\n\n // Inject console object with Node.js-style formatting\n context.evalSync(`\n // Format a single value for console output (Node.js style)\n function __formatForConsole(value, options = {}) {\n const { depth = 2, currentDepth = 0, seen = new WeakSet(), inObject = false } = options;\n\n // Handle null/undefined\n if (value === null) return 'null';\n if (value === undefined) return 'undefined';\n\n // Handle primitives\n const type = typeof value;\n if (type === 'string') {\n // Strings: quoted when inside objects/arrays, raw when top-level console.log arg\n return inObject ? \"'\" + value.replace(/'/g, \"\\\\\\\\'\") + \"'\" : value;\n }\n if (type === 'number' || type === 'boolean') {\n return String(value);\n }\n if (type === 'bigint') {\n return value.toString() + 'n';\n }\n if (type === 'symbol') {\n return value.toString();\n }\n if (type === 'function') {\n const name = value.name || '(anonymous)';\n return '[Function: ' + name + ']';\n }\n\n // Handle objects\n if (type === 'object') {\n // Handle circular references BEFORE depth check (Node.js behavior)\n if (seen.has(value)) {\n return '[Circular]';\n }\n seen.add(value);\n\n // Check depth limit\n if (currentDepth >= depth) {\n if (Array.isArray(value)) return '[Array]';\n return '[Object]';\n }\n\n const nextOptions = { depth, currentDepth: currentDepth + 1, seen, inObject: true };\n\n // Handle Error objects\n if (value instanceof Error) {\n let result = value.name + ': ' + value.message;\n if (value.stack) {\n // Get stack lines after the first line (which is the error message)\n const stackLines = value.stack.split('\\\\n').slice(1);\n if (stackLines.length > 0) {\n result += '\\\\n' + stackLines.join('\\\\n');\n }\n }\n return result;\n }\n\n // Handle Response objects\n if (typeof Response !== 'undefined' && value instanceof Response) {\n return 'Response { status: ' + value.status + ', statusText: ' + __formatForConsole(value.statusText, nextOptions) + ', url: ' + __formatForConsole(value.url, nextOptions) + ' }';\n }\n\n // Handle Request objects\n if (typeof Request !== 'undefined' && value instanceof Request) {\n return 'Request { method: ' + __formatForConsole(value.method, nextOptions) + ', url: ' + __formatForConsole(value.url, nextOptions) + ' }';\n }\n\n // Handle Headers objects\n if (typeof Headers !== 'undefined' && value instanceof Headers) {\n const entries = [];\n value.forEach((v, k) => {\n entries.push(__formatForConsole(k, nextOptions) + ' => ' + __formatForConsole(v, nextOptions));\n });\n return 'Headers { ' + entries.join(', ') + ' }';\n }\n\n // Handle URLSearchParams objects\n if (typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams) {\n const entries = [];\n for (const [k, v] of value) {\n entries.push(__formatForConsole(k, nextOptions) + ' => ' + __formatForConsole(v, nextOptions));\n }\n return entries.length === 0\n ? 'URLSearchParams {}'\n : 'URLSearchParams { ' + entries.join(', ') + ' }';\n }\n\n // Handle URL objects\n if (typeof URL !== 'undefined' && value instanceof URL) {\n const entries = [\n 'href: ' + __formatForConsole(value.href, nextOptions),\n 'origin: ' + __formatForConsole(value.origin, nextOptions),\n 'protocol: ' + __formatForConsole(value.protocol, nextOptions),\n 'username: ' + __formatForConsole(value.username, nextOptions),\n 'password: ' + __formatForConsole(value.password, nextOptions),\n 'host: ' + __formatForConsole(value.host, nextOptions),\n 'hostname: ' + __formatForConsole(value.hostname, nextOptions),\n 'port: ' + __formatForConsole(value.port, nextOptions),\n 'pathname: ' + __formatForConsole(value.pathname, nextOptions),\n 'search: ' + __formatForConsole(value.search, nextOptions),\n 'searchParams: ' + __formatForConsole(value.searchParams, nextOptions),\n 'hash: ' + __formatForConsole(value.hash, nextOptions),\n ];\n return 'URL { ' + entries.join(', ') + ' }';\n }\n\n // Handle Date objects\n if (value instanceof Date) {\n return value.toISOString();\n }\n\n // Handle RegExp\n if (value instanceof RegExp) {\n return value.toString();\n }\n\n // Handle Map\n if (value instanceof Map) {\n const entries = [];\n value.forEach((v, k) => {\n entries.push(__formatForConsole(k, nextOptions) + ' => ' + __formatForConsole(v, nextOptions));\n });\n return 'Map(' + value.size + ') { ' + entries.join(', ') + ' }';\n }\n\n // Handle Set\n if (value instanceof Set) {\n const entries = [];\n value.forEach((v) => {\n entries.push(__formatForConsole(v, nextOptions));\n });\n return 'Set(' + value.size + ') { ' + entries.join(', ') + ' }';\n }\n\n // Handle ArrayBuffer and TypedArrays\n if (value instanceof ArrayBuffer) {\n return 'ArrayBuffer { byteLength: ' + value.byteLength + ' }';\n }\n if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {\n const typedArray = value;\n const name = typedArray.constructor.name;\n const length = typedArray.length;\n if (length <= 10) {\n const items = Array.from(typedArray).map(v => __formatForConsole(v, nextOptions));\n return name + '(' + length + ') [ ' + items.join(', ') + ' ]';\n }\n return name + '(' + length + ') [ ... ]';\n }\n\n // Handle Promise\n if (value instanceof Promise) {\n return 'Promise { <pending> }';\n }\n\n // Handle arrays\n if (Array.isArray(value)) {\n if (value.length === 0) return '[]';\n const items = value.map(item => __formatForConsole(item, nextOptions));\n return '[ ' + items.join(', ') + ' ]';\n }\n\n // Handle plain objects\n const keys = Object.keys(value);\n if (keys.length === 0) return '{}';\n const entries = keys.map(key => {\n const formattedKey = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : __formatForConsole(key, nextOptions);\n return formattedKey + ': ' + __formatForConsole(value[key], nextOptions);\n });\n return '{ ' + entries.join(', ') + ' }';\n }\n\n return String(value);\n }\n\n // Format multiple args with space separation (like console.log)\n function __formatArgs(args) {\n return args.map((arg, i) => __formatForConsole(arg, { inObject: false })).join(' ');\n }\n\n // Format data for console.table - creates ASCII table\n function __formatTable(data, columns) {\n if (data === null || data === undefined) {\n return __formatForConsole(data);\n }\n\n // Convert to array of objects\n let rows = [];\n let headers = new Set();\n\n if (Array.isArray(data)) {\n rows = data.map((item, index) => {\n if (item !== null && typeof item === 'object' && !Array.isArray(item)) {\n Object.keys(item).forEach(k => headers.add(k));\n return { __index: index, ...item };\n }\n return { __index: index, Values: item };\n });\n headers.add('Values');\n } else if (typeof data === 'object') {\n Object.keys(data).forEach(key => {\n const item = data[key];\n if (item !== null && typeof item === 'object' && !Array.isArray(item)) {\n Object.keys(item).forEach(k => headers.add(k));\n rows.push({ __index: key, ...item });\n } else {\n rows.push({ __index: key, Values: item });\n headers.add('Values');\n }\n });\n } else {\n return __formatForConsole(data);\n }\n\n // Filter headers by columns if provided\n let headerList = ['(index)', ...headers];\n headerList = headerList.filter(h => h !== '__index');\n if (columns && Array.isArray(columns)) {\n headerList = ['(index)', ...columns.filter(c => headers.has(c))];\n }\n\n // Calculate column widths\n const colWidths = {};\n headerList.forEach(h => {\n colWidths[h] = h === '(index)' ? 7 : h.length;\n });\n rows.forEach(row => {\n headerList.forEach(h => {\n const key = h === '(index)' ? '__index' : h;\n const val = row[key];\n const formatted = val !== undefined ? __formatForConsole(val, { depth: 1, inObject: true }) : '';\n colWidths[h] = Math.max(colWidths[h], formatted.length);\n });\n });\n\n // Build table\n const sep = '+' + headerList.map(h => '-'.repeat(colWidths[h] + 2)).join('+') + '+';\n const headerRow = '|' + headerList.map(h => ' ' + h.padEnd(colWidths[h]) + ' ').join('|') + '|';\n\n const dataRows = rows.map(row => {\n return '|' + headerList.map(h => {\n const key = h === '(index)' ? '__index' : h;\n const val = row[key];\n const formatted = val !== undefined ? __formatForConsole(val, { depth: 1, inObject: true }) : '';\n return ' ' + formatted.padEnd(colWidths[h]) + ' ';\n }).join('|') + '|';\n });\n\n return [sep, headerRow, sep, ...dataRows, sep].join('\\\\n');\n }\n\n globalThis.console = {\n log: (...args) => __console_log(__formatArgs(args)),\n warn: (...args) => __console_warn(__formatArgs(args)),\n error: (...args) => __console_error(__formatArgs(args)),\n debug: (...args) => __console_debug(__formatArgs(args)),\n info: (...args) => __console_info(__formatArgs(args)),\n trace: (...args) => {\n const err = new Error();\n const stack = err.stack || '';\n // Remove the first two lines (Error and the trace call itself)\n const stackLines = stack.split('\\\\n').slice(2).join('\\\\n');\n __console_trace(__formatArgs(args), 'Trace' + (args.length > 0 ? ': ' + __formatArgs(args) : '') + '\\\\n' + stackLines);\n },\n dir: (value, options) => __console_dir(__formatForConsole(value, { depth: options?.depth ?? 2, inObject: true })),\n table: (data, columns) => __console_table(__formatTable(data, columns)),\n time: __console_time,\n timeEnd: __console_timeEnd,\n timeLog: (label, ...args) => __console_timeLog(label ?? 'default', 0, __formatArgs(args)),\n count: __console_count,\n countReset: __console_countReset,\n group: __console_group,\n groupCollapsed: __console_groupCollapsed,\n groupEnd: __console_groupEnd,\n clear: __console_clear,\n assert: (condition, ...args) => {\n if (!condition) {\n const msg = args.length > 0 ? __formatArgs(args) : 'console.assert';\n __console_assert('Assertion failed: ' + msg);\n }\n },\n };\n `);\n\n return {\n dispose() {\n timers.clear();\n counters.clear();\n groupDepth = 0;\n },\n reset() {\n timers.clear();\n counters.clear();\n groupDepth = 0;\n },\n getTimers() {\n return new Map(timers);\n },\n getCounters() {\n return new Map(counters);\n },\n getGroupDepth() {\n return groupDepth;\n },\n };\n}\n"
|
|
5
|
+
"import ivm from \"@ricsam/isolated-vm\";\nimport { invokeBestEffortEventHandler } from \"../event-callback.cjs\";\n\n/**\n * Console entry types for structured console output.\n * Each entry type captures the specific data needed to render like DevTools.\n * Output is pre-formatted as stdout strings (like Node.js console) inside the sandbox.\n */\nexport type ConsoleEntry =\n | {\n type: \"output\";\n level: \"log\" | \"warn\" | \"error\" | \"info\" | \"debug\";\n stdout: string;\n groupDepth: number;\n }\n | {\n /** Browser console output (from Playwright page, not sandbox) */\n type: \"browserOutput\";\n level: string;\n stdout: string;\n location?: {\n url?: string;\n lineNumber?: number;\n columnNumber?: number;\n };\n timestamp: number;\n }\n | { type: \"dir\"; stdout: string; groupDepth: number }\n | { type: \"table\"; stdout: string; groupDepth: number }\n | { type: \"time\"; label: string; duration: number; groupDepth: number }\n | {\n type: \"timeLog\";\n label: string;\n duration: number;\n stdout: string;\n groupDepth: number;\n }\n | { type: \"count\"; label: string; count: number; groupDepth: number }\n | { type: \"countReset\"; label: string; groupDepth: number }\n | { type: \"assert\"; stdout: string; groupDepth: number }\n | {\n type: \"group\";\n label: string;\n collapsed: boolean;\n groupDepth: number;\n }\n | { type: \"groupEnd\"; groupDepth: number }\n | { type: \"clear\" }\n | { type: \"trace\"; stdout: string; stack: string; groupDepth: number };\n\n/**\n * Console options with a single structured callback.\n */\nexport interface ConsoleOptions {\n /**\n * Sync-only, best-effort callback invoked for each console operation.\n * Receives a structured entry with all data needed to render the output.\n * Returned promises are ignored.\n */\n onEntry?: (entry: ConsoleEntry) => void;\n}\n\n/**\n * Console handle for accessing internal state.\n */\nexport interface ConsoleHandle {\n dispose(): void;\n reset(): void;\n getTimers(): Map<string, number>;\n getCounters(): Map<string, number>;\n getGroupDepth(): number;\n}\n\n\n/**\n * Setup console API in an isolated-vm context\n *\n * Injects console.log, console.warn, console.error, console.info, console.debug,\n * console.trace, console.dir, console.table, console.time, console.timeEnd,\n * console.timeLog, console.count, console.countReset, console.group,\n * console.groupCollapsed, console.groupEnd, console.clear, console.assert\n *\n * @example\n * const handle = await setupConsole(context, {\n * onEntry: (entry) => {\n * if (entry.type === 'output') {\n * console.log(`[${entry.level}]`, ...entry.args);\n * }\n * }\n * });\n */\nexport async function setupConsole(\n context: ivm.Context,\n options?: ConsoleOptions\n): Promise<ConsoleHandle> {\n const opts = options ?? {};\n const emitEntry = (entry: ConsoleEntry): void => {\n invokeBestEffortEventHandler(\"console.onEntry\", opts.onEntry, entry);\n };\n\n // State management\n const timers = new Map<string, number>();\n const counters = new Map<string, number>();\n let groupDepth = 0;\n\n const global = context.global;\n\n // Log-level methods (output type)\n const logLevels = [\"log\", \"warn\", \"error\", \"debug\", \"info\"] as const;\n\n for (const level of logLevels) {\n global.setSync(\n `__console_${level}`,\n new ivm.Callback((stdout: string) => {\n emitEntry({\n type: \"output\",\n level,\n stdout,\n groupDepth,\n });\n })\n );\n }\n\n // dir method\n global.setSync(\n \"__console_dir\",\n new ivm.Callback((stdout: string) => {\n emitEntry({\n type: \"dir\",\n stdout,\n groupDepth,\n });\n })\n );\n\n // table method\n global.setSync(\n \"__console_table\",\n new ivm.Callback((stdout: string) => {\n emitEntry({\n type: \"table\",\n stdout,\n groupDepth,\n });\n })\n );\n\n // trace method (includes stack)\n global.setSync(\n \"__console_trace\",\n new ivm.Callback((stdout: string, stack: string) => {\n emitEntry({\n type: \"trace\",\n stdout,\n stack,\n groupDepth,\n });\n })\n );\n\n // Timing methods\n global.setSync(\n \"__console_time\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n timers.set(l, performance.now());\n })\n );\n\n global.setSync(\n \"__console_timeEnd\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n const start = timers.get(l);\n if (start !== undefined) {\n const duration = performance.now() - start;\n timers.delete(l);\n emitEntry({\n type: \"time\",\n label: l,\n duration,\n groupDepth,\n });\n }\n })\n );\n\n global.setSync(\n \"__console_timeLog\",\n new ivm.Callback((label: string, duration: number, stdout: string) => {\n const l = label ?? \"default\";\n const start = timers.get(l);\n if (start !== undefined) {\n const actualDuration = performance.now() - start;\n emitEntry({\n type: \"timeLog\",\n label: l,\n duration: actualDuration,\n stdout,\n groupDepth,\n });\n }\n })\n );\n\n // Counting methods\n global.setSync(\n \"__console_count\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n const count = (counters.get(l) ?? 0) + 1;\n counters.set(l, count);\n emitEntry({\n type: \"count\",\n label: l,\n count,\n groupDepth,\n });\n })\n );\n\n global.setSync(\n \"__console_countReset\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n counters.delete(l);\n emitEntry({\n type: \"countReset\",\n label: l,\n groupDepth,\n });\n })\n );\n\n // Grouping methods\n global.setSync(\n \"__console_group\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n emitEntry({\n type: \"group\",\n label: l,\n collapsed: false,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupCollapsed\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n emitEntry({\n type: \"group\",\n label: l,\n collapsed: true,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupEnd\",\n new ivm.Callback(() => {\n if (groupDepth > 0) {\n groupDepth--;\n }\n emitEntry({\n type: \"groupEnd\",\n groupDepth,\n });\n })\n );\n\n // Other methods\n global.setSync(\n \"__console_clear\",\n new ivm.Callback(() => {\n emitEntry({ type: \"clear\" });\n })\n );\n\n global.setSync(\n \"__console_assert\",\n new ivm.Callback((stdout: string) => {\n emitEntry({\n type: \"assert\",\n stdout,\n groupDepth,\n });\n })\n );\n\n // Inject console object with Node.js-style formatting\n context.evalSync(`\n // Format a single value for console output (Node.js style)\n function __formatForConsole(value, options = {}) {\n const { depth = 2, currentDepth = 0, seen = new WeakSet(), inObject = false } = options;\n\n // Handle null/undefined\n if (value === null) return 'null';\n if (value === undefined) return 'undefined';\n\n // Handle primitives\n const type = typeof value;\n if (type === 'string') {\n // Strings: quoted when inside objects/arrays, raw when top-level console.log arg\n return inObject ? \"'\" + value.replace(/'/g, \"\\\\\\\\'\") + \"'\" : value;\n }\n if (type === 'number' || type === 'boolean') {\n return String(value);\n }\n if (type === 'bigint') {\n return value.toString() + 'n';\n }\n if (type === 'symbol') {\n return value.toString();\n }\n if (type === 'function') {\n const name = value.name || '(anonymous)';\n return '[Function: ' + name + ']';\n }\n\n // Handle objects\n if (type === 'object') {\n // Handle circular references BEFORE depth check (Node.js behavior)\n if (seen.has(value)) {\n return '[Circular]';\n }\n seen.add(value);\n\n // Check depth limit\n if (currentDepth >= depth) {\n if (Array.isArray(value)) return '[Array]';\n return '[Object]';\n }\n\n const nextOptions = { depth, currentDepth: currentDepth + 1, seen, inObject: true };\n\n // Handle Error objects\n if (value instanceof Error) {\n let result = value.name + ': ' + value.message;\n if (value.stack) {\n // Get stack lines after the first line (which is the error message)\n const stackLines = value.stack.split('\\\\n').slice(1);\n if (stackLines.length > 0) {\n result += '\\\\n' + stackLines.join('\\\\n');\n }\n }\n return result;\n }\n\n // Handle Response objects\n if (typeof Response !== 'undefined' && value instanceof Response) {\n return 'Response { status: ' + value.status + ', statusText: ' + __formatForConsole(value.statusText, nextOptions) + ', url: ' + __formatForConsole(value.url, nextOptions) + ' }';\n }\n\n // Handle Request objects\n if (typeof Request !== 'undefined' && value instanceof Request) {\n return 'Request { method: ' + __formatForConsole(value.method, nextOptions) + ', url: ' + __formatForConsole(value.url, nextOptions) + ' }';\n }\n\n // Handle Headers objects\n if (typeof Headers !== 'undefined' && value instanceof Headers) {\n const entries = [];\n value.forEach((v, k) => {\n entries.push(__formatForConsole(k, nextOptions) + ' => ' + __formatForConsole(v, nextOptions));\n });\n return 'Headers { ' + entries.join(', ') + ' }';\n }\n\n // Handle URLSearchParams objects\n if (typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams) {\n const entries = [];\n for (const [k, v] of value) {\n entries.push(__formatForConsole(k, nextOptions) + ' => ' + __formatForConsole(v, nextOptions));\n }\n return entries.length === 0\n ? 'URLSearchParams {}'\n : 'URLSearchParams { ' + entries.join(', ') + ' }';\n }\n\n // Handle URL objects\n if (typeof URL !== 'undefined' && value instanceof URL) {\n const entries = [\n 'href: ' + __formatForConsole(value.href, nextOptions),\n 'origin: ' + __formatForConsole(value.origin, nextOptions),\n 'protocol: ' + __formatForConsole(value.protocol, nextOptions),\n 'username: ' + __formatForConsole(value.username, nextOptions),\n 'password: ' + __formatForConsole(value.password, nextOptions),\n 'host: ' + __formatForConsole(value.host, nextOptions),\n 'hostname: ' + __formatForConsole(value.hostname, nextOptions),\n 'port: ' + __formatForConsole(value.port, nextOptions),\n 'pathname: ' + __formatForConsole(value.pathname, nextOptions),\n 'search: ' + __formatForConsole(value.search, nextOptions),\n 'searchParams: ' + __formatForConsole(value.searchParams, nextOptions),\n 'hash: ' + __formatForConsole(value.hash, nextOptions),\n ];\n return 'URL { ' + entries.join(', ') + ' }';\n }\n\n // Handle Date objects\n if (value instanceof Date) {\n return value.toISOString();\n }\n\n // Handle RegExp\n if (value instanceof RegExp) {\n return value.toString();\n }\n\n // Handle Map\n if (value instanceof Map) {\n const entries = [];\n value.forEach((v, k) => {\n entries.push(__formatForConsole(k, nextOptions) + ' => ' + __formatForConsole(v, nextOptions));\n });\n return 'Map(' + value.size + ') { ' + entries.join(', ') + ' }';\n }\n\n // Handle Set\n if (value instanceof Set) {\n const entries = [];\n value.forEach((v) => {\n entries.push(__formatForConsole(v, nextOptions));\n });\n return 'Set(' + value.size + ') { ' + entries.join(', ') + ' }';\n }\n\n // Handle ArrayBuffer and TypedArrays\n if (value instanceof ArrayBuffer) {\n return 'ArrayBuffer { byteLength: ' + value.byteLength + ' }';\n }\n if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {\n const typedArray = value;\n const name = typedArray.constructor.name;\n const length = typedArray.length;\n if (length <= 10) {\n const items = Array.from(typedArray).map(v => __formatForConsole(v, nextOptions));\n return name + '(' + length + ') [ ' + items.join(', ') + ' ]';\n }\n return name + '(' + length + ') [ ... ]';\n }\n\n // Handle Promise\n if (value instanceof Promise) {\n return 'Promise { <pending> }';\n }\n\n // Handle arrays\n if (Array.isArray(value)) {\n if (value.length === 0) return '[]';\n const items = value.map(item => __formatForConsole(item, nextOptions));\n return '[ ' + items.join(', ') + ' ]';\n }\n\n // Handle plain objects\n const keys = Object.keys(value);\n if (keys.length === 0) return '{}';\n const entries = keys.map(key => {\n const formattedKey = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : __formatForConsole(key, nextOptions);\n return formattedKey + ': ' + __formatForConsole(value[key], nextOptions);\n });\n return '{ ' + entries.join(', ') + ' }';\n }\n\n return String(value);\n }\n\n // Format multiple args with space separation (like console.log)\n function __formatArgs(args) {\n return args.map((arg, i) => __formatForConsole(arg, { inObject: false })).join(' ');\n }\n\n // Format data for console.table - creates ASCII table\n function __formatTable(data, columns) {\n if (data === null || data === undefined) {\n return __formatForConsole(data);\n }\n\n // Convert to array of objects\n let rows = [];\n let headers = new Set();\n\n if (Array.isArray(data)) {\n rows = data.map((item, index) => {\n if (item !== null && typeof item === 'object' && !Array.isArray(item)) {\n Object.keys(item).forEach(k => headers.add(k));\n return { __index: index, ...item };\n }\n return { __index: index, Values: item };\n });\n headers.add('Values');\n } else if (typeof data === 'object') {\n Object.keys(data).forEach(key => {\n const item = data[key];\n if (item !== null && typeof item === 'object' && !Array.isArray(item)) {\n Object.keys(item).forEach(k => headers.add(k));\n rows.push({ __index: key, ...item });\n } else {\n rows.push({ __index: key, Values: item });\n headers.add('Values');\n }\n });\n } else {\n return __formatForConsole(data);\n }\n\n // Filter headers by columns if provided\n let headerList = ['(index)', ...headers];\n headerList = headerList.filter(h => h !== '__index');\n if (columns && Array.isArray(columns)) {\n headerList = ['(index)', ...columns.filter(c => headers.has(c))];\n }\n\n // Calculate column widths\n const colWidths = {};\n headerList.forEach(h => {\n colWidths[h] = h === '(index)' ? 7 : h.length;\n });\n rows.forEach(row => {\n headerList.forEach(h => {\n const key = h === '(index)' ? '__index' : h;\n const val = row[key];\n const formatted = val !== undefined ? __formatForConsole(val, { depth: 1, inObject: true }) : '';\n colWidths[h] = Math.max(colWidths[h], formatted.length);\n });\n });\n\n // Build table\n const sep = '+' + headerList.map(h => '-'.repeat(colWidths[h] + 2)).join('+') + '+';\n const headerRow = '|' + headerList.map(h => ' ' + h.padEnd(colWidths[h]) + ' ').join('|') + '|';\n\n const dataRows = rows.map(row => {\n return '|' + headerList.map(h => {\n const key = h === '(index)' ? '__index' : h;\n const val = row[key];\n const formatted = val !== undefined ? __formatForConsole(val, { depth: 1, inObject: true }) : '';\n return ' ' + formatted.padEnd(colWidths[h]) + ' ';\n }).join('|') + '|';\n });\n\n return [sep, headerRow, sep, ...dataRows, sep].join('\\\\n');\n }\n\n globalThis.console = {\n log: (...args) => __console_log(__formatArgs(args)),\n warn: (...args) => __console_warn(__formatArgs(args)),\n error: (...args) => __console_error(__formatArgs(args)),\n debug: (...args) => __console_debug(__formatArgs(args)),\n info: (...args) => __console_info(__formatArgs(args)),\n trace: (...args) => {\n const err = new Error();\n const stack = err.stack || '';\n // Remove the first two lines (Error and the trace call itself)\n const stackLines = stack.split('\\\\n').slice(2).join('\\\\n');\n __console_trace(__formatArgs(args), 'Trace' + (args.length > 0 ? ': ' + __formatArgs(args) : '') + '\\\\n' + stackLines);\n },\n dir: (value, options) => __console_dir(__formatForConsole(value, { depth: options?.depth ?? 2, inObject: true })),\n table: (data, columns) => __console_table(__formatTable(data, columns)),\n time: __console_time,\n timeEnd: __console_timeEnd,\n timeLog: (label, ...args) => __console_timeLog(label ?? 'default', 0, __formatArgs(args)),\n count: __console_count,\n countReset: __console_countReset,\n group: __console_group,\n groupCollapsed: __console_groupCollapsed,\n groupEnd: __console_groupEnd,\n clear: __console_clear,\n assert: (condition, ...args) => {\n if (!condition) {\n const msg = args.length > 0 ? __formatArgs(args) : 'console.assert';\n __console_assert('Assertion failed: ' + msg);\n }\n },\n };\n `);\n\n return {\n dispose() {\n timers.clear();\n counters.clear();\n groupDepth = 0;\n },\n reset() {\n timers.clear();\n counters.clear();\n groupDepth = 0;\n },\n getTimers() {\n return new Map(timers);\n },\n getCounters() {\n return new Map(counters);\n },\n getGroupDepth() {\n return groupDepth;\n },\n };\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAgB,IAAhB;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAgB,IAAhB;AAC6C,IAA7C;AA0FA,eAAsB,YAAY,CAChC,SACA,SACwB;AAAA,EACxB,MAAM,OAAO,WAAW,CAAC;AAAA,EACzB,MAAM,YAAY,CAAC,UAA8B;AAAA,IAC/C,mDAA6B,mBAAmB,KAAK,SAAS,KAAK;AAAA;AAAA,EAIrE,MAAM,SAAS,IAAI;AAAA,EACnB,MAAM,WAAW,IAAI;AAAA,EACrB,IAAI,aAAa;AAAA,EAEjB,MAAM,SAAS,QAAQ;AAAA,EAGvB,MAAM,YAAY,CAAC,OAAO,QAAQ,SAAS,SAAS,MAAM;AAAA,EAE1D,WAAW,SAAS,WAAW;AAAA,IAC7B,OAAO,QACL,aAAa,SACb,IAAI,2BAAI,SAAS,CAAC,WAAmB;AAAA,MACnC,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AA;AAAA,EAEX;AAAA;",
|
|
8
|
+
"debugId": "9D90A82ECBFF1C6364756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -53,6 +53,11 @@ var NULL_BODY_STATUSES = new Set([101, 103, 204, 205, 304]);
|
|
|
53
53
|
var DEFAULT_CALLBACK_TIMEOUT_MS = 120000;
|
|
54
54
|
var FETCH_CALLBACK_TIMEOUT_MS = 35000;
|
|
55
55
|
var requestContextStorage = new import_node_async_hooks.AsyncLocalStorage;
|
|
56
|
+
function invokeBestEffortClientEventCallback(connection, callbackId, args, label, options) {
|
|
57
|
+
invokeClientCallback(connection, callbackId, args, options).catch((error) => {
|
|
58
|
+
console.error(`[isolate-daemon] ${label} delivery failed.`, error);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
56
61
|
function createAbortError(reason = "The operation was aborted") {
|
|
57
62
|
if (typeof DOMException !== "undefined") {
|
|
58
63
|
return new DOMException(reason, "AbortError");
|
|
@@ -425,7 +430,6 @@ function softDeleteRuntime(instance, state, reason) {
|
|
|
425
430
|
instance.callbacks.clear();
|
|
426
431
|
instance.runtime.timers.clearAll();
|
|
427
432
|
instance.runtime.console.reset();
|
|
428
|
-
instance.runtime.pendingCallbacks.length = 0;
|
|
429
433
|
instance.returnedCallbacks?.clear();
|
|
430
434
|
instance.returnedPromises?.clear();
|
|
431
435
|
instance.returnedIterators?.clear();
|
|
@@ -894,8 +898,7 @@ async function handleCreateRuntime(message, connection, state) {
|
|
|
894
898
|
if (!conn || callbackId === undefined) {
|
|
895
899
|
return;
|
|
896
900
|
}
|
|
897
|
-
|
|
898
|
-
instance.runtime?.pendingCallbacks?.push(promise);
|
|
901
|
+
invokeBestEffortClientEventCallback(conn, callbackId, [JSON.stringify(event)], "testEnvironment.onEvent", { signal: getCurrentHostSignal(instance) });
|
|
899
902
|
} : undefined,
|
|
900
903
|
testTimeout: testEnvOptions?.testTimeout
|
|
901
904
|
};
|
|
@@ -928,14 +931,11 @@ async function handleCreateRuntime(message, connection, state) {
|
|
|
928
931
|
return;
|
|
929
932
|
}
|
|
930
933
|
if (event.type === "browserConsoleLog" && callbackContext.playwright.onBrowserConsoleLogCallbackId !== undefined) {
|
|
931
|
-
|
|
932
|
-
instance.runtime?.pendingCallbacks?.push(promise);
|
|
934
|
+
invokeBestEffortClientEventCallback(conn, callbackContext.playwright.onBrowserConsoleLogCallbackId, [{ level: event.level, stdout: event.stdout, timestamp: event.timestamp }], "playwright.onBrowserConsoleLog", { signal: getCurrentHostSignal(instance) });
|
|
933
935
|
} else if (event.type === "networkRequest" && callbackContext.playwright.onNetworkRequestCallbackId !== undefined) {
|
|
934
|
-
|
|
935
|
-
instance.runtime?.pendingCallbacks?.push(promise);
|
|
936
|
+
invokeBestEffortClientEventCallback(conn, callbackContext.playwright.onNetworkRequestCallbackId, [event], "playwright.onNetworkRequest", { signal: getCurrentHostSignal(instance) });
|
|
936
937
|
} else if (event.type === "networkResponse" && callbackContext.playwright.onNetworkResponseCallbackId !== undefined) {
|
|
937
|
-
|
|
938
|
-
instance.runtime?.pendingCallbacks?.push(promise);
|
|
938
|
+
invokeBestEffortClientEventCallback(conn, callbackContext.playwright.onNetworkResponseCallbackId, [event], "playwright.onNetworkResponse", { signal: getCurrentHostSignal(instance) });
|
|
939
939
|
}
|
|
940
940
|
}
|
|
941
941
|
};
|
|
@@ -950,8 +950,7 @@ async function handleCreateRuntime(message, connection, state) {
|
|
|
950
950
|
const callbackId = callbackContext.consoleOnEntry;
|
|
951
951
|
if (!conn || callbackId === undefined)
|
|
952
952
|
return;
|
|
953
|
-
|
|
954
|
-
runtime.pendingCallbacks.push(promise);
|
|
953
|
+
invokeBestEffortClientEventCallback(conn, callbackId, [entry], "console.onEntry");
|
|
955
954
|
}
|
|
956
955
|
},
|
|
957
956
|
fetch: async (url, init) => {
|
|
@@ -2251,4 +2250,4 @@ async function handleClearCollectedData(message, connection, state) {
|
|
|
2251
2250
|
}
|
|
2252
2251
|
}
|
|
2253
2252
|
|
|
2254
|
-
//# debugId=
|
|
2253
|
+
//# debugId=03B1B78DAE609D0164756E2164756E21
|