@tontoko/fast-playwright-mcp 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +1047 -0
- package/cli.js +18 -0
- package/config.d.ts +124 -0
- package/index.d.ts +25 -0
- package/index.js +18 -0
- package/lib/actions.d.js +0 -0
- package/lib/batch/batch-executor.js +137 -0
- package/lib/browser-context-factory.js +252 -0
- package/lib/browser-server-backend.js +139 -0
- package/lib/config/constants.js +80 -0
- package/lib/config.js +405 -0
- package/lib/context.js +274 -0
- package/lib/diagnostics/common/diagnostic-base.js +63 -0
- package/lib/diagnostics/common/error-enrichment-utils.js +212 -0
- package/lib/diagnostics/common/index.js +56 -0
- package/lib/diagnostics/common/initialization-manager.js +210 -0
- package/lib/diagnostics/common/performance-tracker.js +132 -0
- package/lib/diagnostics/diagnostic-error.js +140 -0
- package/lib/diagnostics/diagnostic-level.js +123 -0
- package/lib/diagnostics/diagnostic-thresholds.js +347 -0
- package/lib/diagnostics/element-discovery.js +441 -0
- package/lib/diagnostics/enhanced-error-handler.js +376 -0
- package/lib/diagnostics/error-enrichment.js +157 -0
- package/lib/diagnostics/frame-reference-manager.js +179 -0
- package/lib/diagnostics/page-analyzer.js +639 -0
- package/lib/diagnostics/parallel-page-analyzer.js +129 -0
- package/lib/diagnostics/resource-manager.js +134 -0
- package/lib/diagnostics/smart-config.js +482 -0
- package/lib/diagnostics/smart-handle.js +118 -0
- package/lib/diagnostics/unified-system.js +717 -0
- package/lib/extension/cdp-relay.js +486 -0
- package/lib/extension/extension-context-factory.js +74 -0
- package/lib/extension/main.js +41 -0
- package/lib/file-utils.js +42 -0
- package/lib/generate-keys.js +75 -0
- package/lib/http-server.js +50 -0
- package/lib/in-process-client.js +64 -0
- package/lib/index.js +48 -0
- package/lib/javascript.js +90 -0
- package/lib/log.js +33 -0
- package/lib/loop/loop-claude.js +247 -0
- package/lib/loop/loop-open-ai.js +222 -0
- package/lib/loop/loop.js +174 -0
- package/lib/loop/main.js +46 -0
- package/lib/loopTools/context.js +76 -0
- package/lib/loopTools/main.js +65 -0
- package/lib/loopTools/perform.js +40 -0
- package/lib/loopTools/snapshot.js +37 -0
- package/lib/loopTools/tool.js +26 -0
- package/lib/manual-promise.js +125 -0
- package/lib/mcp/in-process-transport.js +91 -0
- package/lib/mcp/proxy-backend.js +127 -0
- package/lib/mcp/server.js +123 -0
- package/lib/mcp/transport.js +159 -0
- package/lib/package.js +28 -0
- package/lib/program.js +82 -0
- package/lib/response.js +493 -0
- package/lib/schemas/expectation.js +152 -0
- package/lib/session-log.js +210 -0
- package/lib/tab.js +417 -0
- package/lib/tools/base-tool-handler.js +141 -0
- package/lib/tools/batch-execute.js +150 -0
- package/lib/tools/common.js +65 -0
- package/lib/tools/console.js +60 -0
- package/lib/tools/diagnose/diagnose-analysis-runner.js +101 -0
- package/lib/tools/diagnose/diagnose-config-handler.js +130 -0
- package/lib/tools/diagnose/diagnose-report-builder.js +394 -0
- package/lib/tools/diagnose.js +147 -0
- package/lib/tools/dialogs.js +57 -0
- package/lib/tools/evaluate.js +67 -0
- package/lib/tools/files.js +53 -0
- package/lib/tools/find-elements.js +307 -0
- package/lib/tools/install.js +60 -0
- package/lib/tools/keyboard.js +93 -0
- package/lib/tools/mouse.js +110 -0
- package/lib/tools/navigate.js +82 -0
- package/lib/tools/network.js +50 -0
- package/lib/tools/pdf.js +46 -0
- package/lib/tools/screenshot.js +113 -0
- package/lib/tools/snapshot.js +158 -0
- package/lib/tools/tabs.js +97 -0
- package/lib/tools/tool.js +47 -0
- package/lib/tools/utils.js +131 -0
- package/lib/tools/wait.js +64 -0
- package/lib/tools.js +65 -0
- package/lib/types/batch.js +47 -0
- package/lib/types/diff.js +0 -0
- package/lib/types/performance.js +0 -0
- package/lib/types/threshold-base.js +0 -0
- package/lib/utils/array-utils.js +44 -0
- package/lib/utils/code-deduplication-utils.js +141 -0
- package/lib/utils/common-formatters.js +252 -0
- package/lib/utils/console-filter.js +64 -0
- package/lib/utils/diagnostic-report-utils.js +178 -0
- package/lib/utils/diff-formatter.js +126 -0
- package/lib/utils/disposable-manager.js +135 -0
- package/lib/utils/error-handler-middleware.js +77 -0
- package/lib/utils/image-processor.js +137 -0
- package/lib/utils/index.js +92 -0
- package/lib/utils/report-builder.js +189 -0
- package/lib/utils/request-logger.js +82 -0
- package/lib/utils/response-diff-detector.js +150 -0
- package/lib/utils/section-builder.js +62 -0
- package/lib/utils/tool-patterns.js +153 -0
- package/lib/utils.js +46 -0
- package/package.json +77 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
19
|
+
|
|
20
|
+
// src/diagnostics/frame-reference-manager.ts
|
|
21
|
+
import debug from "debug";
|
|
22
|
+
var frameDebug = debug("pw:mcp:frame");
|
|
23
|
+
|
|
24
|
+
class FrameReferenceManager {
|
|
25
|
+
frameRefs = new WeakMap;
|
|
26
|
+
activeFrames = new Set;
|
|
27
|
+
cleanupInterval = null;
|
|
28
|
+
disposed = false;
|
|
29
|
+
constructor() {
|
|
30
|
+
this.startCleanupTimer();
|
|
31
|
+
}
|
|
32
|
+
trackFrame(frame) {
|
|
33
|
+
if (this.disposed) {
|
|
34
|
+
throw new Error("FrameReferenceManager has been disposed");
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const metadata = {
|
|
38
|
+
url: frame.url() ?? "about:blank",
|
|
39
|
+
name: frame.name() ?? null,
|
|
40
|
+
parentFrame: frame.parentFrame(),
|
|
41
|
+
isDetached: false,
|
|
42
|
+
timestamp: Date.now()
|
|
43
|
+
};
|
|
44
|
+
this.frameRefs.set(frame, metadata);
|
|
45
|
+
this.activeFrames.add(frame);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
frameDebug("Frame tracking failed (frame might be detached):", {
|
|
48
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
untrackFrame(frame) {
|
|
53
|
+
this.activeFrames.delete(frame);
|
|
54
|
+
}
|
|
55
|
+
getFrameMetadata(frame) {
|
|
56
|
+
return this.frameRefs.get(frame);
|
|
57
|
+
}
|
|
58
|
+
getActiveFrames() {
|
|
59
|
+
return Array.from(this.activeFrames);
|
|
60
|
+
}
|
|
61
|
+
updateElementCount(frame, count) {
|
|
62
|
+
const metadata = this.frameRefs.get(frame);
|
|
63
|
+
if (metadata) {
|
|
64
|
+
metadata.elementCount = count;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async cleanupDetachedFrames() {
|
|
68
|
+
if (this.disposed) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const framesToRemove = [];
|
|
72
|
+
const frameCheckPromises = Array.from(this.activeFrames).map(async (frame) => {
|
|
73
|
+
try {
|
|
74
|
+
await Promise.race([
|
|
75
|
+
frame.url(),
|
|
76
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("Timeout")), 1000))
|
|
77
|
+
]);
|
|
78
|
+
return { frame, isDetached: false };
|
|
79
|
+
} catch (error) {
|
|
80
|
+
let frameUrl = "unknown";
|
|
81
|
+
try {
|
|
82
|
+
frameUrl = frame.url();
|
|
83
|
+
} catch (urlError) {
|
|
84
|
+
frameDebug("Could not retrieve frame URL:", urlError);
|
|
85
|
+
}
|
|
86
|
+
frameDebug("Frame accessibility check failed (frame likely detached):", {
|
|
87
|
+
url: frameUrl,
|
|
88
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
89
|
+
});
|
|
90
|
+
return { frame, isDetached: true };
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
const frameCheckResults = await Promise.all(frameCheckPromises);
|
|
94
|
+
for (const { frame, isDetached } of frameCheckResults) {
|
|
95
|
+
if (isDetached) {
|
|
96
|
+
const metadata = this.frameRefs.get(frame);
|
|
97
|
+
if (metadata) {
|
|
98
|
+
metadata.isDetached = true;
|
|
99
|
+
}
|
|
100
|
+
framesToRemove.push(frame);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
for (const frame of framesToRemove) {
|
|
104
|
+
this.activeFrames.delete(frame);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
getStatistics() {
|
|
108
|
+
let detachedCount = 0;
|
|
109
|
+
let totalElements = 0;
|
|
110
|
+
let framesWithElementCount = 0;
|
|
111
|
+
for (const frame of Array.from(this.activeFrames)) {
|
|
112
|
+
const metadata = this.frameRefs.get(frame);
|
|
113
|
+
if (metadata) {
|
|
114
|
+
if (metadata.isDetached) {
|
|
115
|
+
detachedCount++;
|
|
116
|
+
}
|
|
117
|
+
if (typeof metadata.elementCount === "number") {
|
|
118
|
+
totalElements += metadata.elementCount;
|
|
119
|
+
framesWithElementCount++;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const averageElementCount = framesWithElementCount > 0 ? totalElements / framesWithElementCount : 0;
|
|
124
|
+
return {
|
|
125
|
+
activeCount: this.activeFrames.size,
|
|
126
|
+
totalTracked: this.activeFrames.size,
|
|
127
|
+
detachedCount,
|
|
128
|
+
averageElementCount: Math.round(averageElementCount)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
findPerformanceIssues() {
|
|
132
|
+
const now = Date.now();
|
|
133
|
+
const largeFrames = [];
|
|
134
|
+
const oldFrames = [];
|
|
135
|
+
for (const frame of Array.from(this.activeFrames)) {
|
|
136
|
+
const metadata = this.frameRefs.get(frame);
|
|
137
|
+
if (metadata && !metadata.isDetached) {
|
|
138
|
+
if (typeof metadata.elementCount === "number" && metadata.elementCount > 1000) {
|
|
139
|
+
largeFrames.push({
|
|
140
|
+
frame,
|
|
141
|
+
elementCount: metadata.elementCount,
|
|
142
|
+
url: metadata.url
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const age = now - metadata.timestamp;
|
|
146
|
+
if (age > 300000) {
|
|
147
|
+
oldFrames.push({
|
|
148
|
+
frame,
|
|
149
|
+
age,
|
|
150
|
+
url: metadata.url
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { largeFrames, oldFrames };
|
|
156
|
+
}
|
|
157
|
+
startCleanupTimer() {
|
|
158
|
+
this.cleanupInterval = setInterval(() => {
|
|
159
|
+
this.cleanupDetachedFrames().catch((error) => {
|
|
160
|
+
frameDebug("Frame cleanup timer failed:", error instanceof Error ? error.message : "Unknown error");
|
|
161
|
+
});
|
|
162
|
+
}, 30000);
|
|
163
|
+
}
|
|
164
|
+
async dispose() {
|
|
165
|
+
if (this.disposed) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (this.cleanupInterval) {
|
|
169
|
+
clearInterval(this.cleanupInterval);
|
|
170
|
+
this.cleanupInterval = null;
|
|
171
|
+
}
|
|
172
|
+
await this.cleanupDetachedFrames();
|
|
173
|
+
this.activeFrames.clear();
|
|
174
|
+
this.disposed = true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
export {
|
|
178
|
+
FrameReferenceManager
|
|
179
|
+
};
|