@tontoko/fast-playwright-mcp 0.1.1 → 0.1.3

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.
@@ -0,0 +1,106 @@
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/types/html-inspection.ts
21
+ import { z } from "zod";
22
+ import { elementSelectorSchema } from "./selectors.js";
23
+ var htmlInspectionOptionsSchema = z.object({
24
+ selectors: z.array(elementSelectorSchema).min(1).describe("Array of element selectors to inspect"),
25
+ depth: z.number().min(1).max(10).optional().default(2).describe("Maximum hierarchy depth to extract"),
26
+ includeStyles: z.boolean().optional().default(false).describe("Include computed CSS styles"),
27
+ maxSize: z.number().min(1024).max(500000).optional().default(50000).describe("Maximum size in bytes (1KB-500KB)"),
28
+ format: z.enum(["html", "aria", "text"]).optional().default("html").describe("Output format"),
29
+ includeAttributes: z.boolean().optional().default(true).describe("Include element attributes"),
30
+ preserveWhitespace: z.boolean().optional().default(false).describe("Preserve whitespace in content"),
31
+ excludeSelector: z.string().optional().describe("CSS selector to exclude elements")
32
+ });
33
+ var HTMLInspectionError = {
34
+ SELECTOR_NOT_FOUND: "SELECTOR_NOT_FOUND",
35
+ SIZE_LIMIT_EXCEEDED: "SIZE_LIMIT_EXCEEDED",
36
+ EXTRACTION_TIMEOUT: "EXTRACTION_TIMEOUT",
37
+ INVALID_SELECTOR: "INVALID_SELECTOR",
38
+ DOM_ACCESS_ERROR: "DOM_ACCESS_ERROR"
39
+ };
40
+ function calculateHtmlSize(html) {
41
+ return new TextEncoder().encode(html).length;
42
+ }
43
+ function truncateHtml(html, maxSize) {
44
+ if (calculateHtmlSize(html) <= maxSize) {
45
+ return { html, truncated: false };
46
+ }
47
+ const truncated = html.substring(0, maxSize - 100);
48
+ const lastTag = truncated.lastIndexOf("<");
49
+ const safeHtml = lastTag > truncated.lastIndexOf(">") ? truncated.substring(0, lastTag) : truncated;
50
+ return { html: `${safeHtml}<!-- TRUNCATED -->`, truncated: true };
51
+ }
52
+ function validateHTMLInspectionOptions(options) {
53
+ return htmlInspectionOptionsSchema.parse(options);
54
+ }
55
+ function generateHTMLInspectionSuggestions(result) {
56
+ const suggestions = [];
57
+ if (result.truncated) {
58
+ suggestions.push("Content was truncated. Consider reducing depth or using more specific selectors.");
59
+ }
60
+ if (result.stats.selectorsNotFound > 0) {
61
+ suggestions.push("Some selectors did not match elements. Try using more specific or alternative selectors.");
62
+ }
63
+ if (result.timing.totalMs > 5000) {
64
+ suggestions.push("Inspection took longer than expected. Consider reducing scope or depth.");
65
+ }
66
+ if (result.stats.averageDepth > 5) {
67
+ suggestions.push("Deep element extraction detected. Consider limiting depth for better performance.");
68
+ }
69
+ return suggestions;
70
+ }
71
+ var HTMLInspectionUtils = {
72
+ calculateHtmlSize,
73
+ truncateHtml,
74
+ validateOptions: validateHTMLInspectionOptions,
75
+ generateSuggestions: generateHTMLInspectionSuggestions
76
+ };
77
+ var HTMLInspectionConstants = {
78
+ DEFAULT_MAX_SIZE: 50000,
79
+ DEFAULT_DEPTH: 2,
80
+ MAX_DEPTH: 10,
81
+ DEFAULT_TIMEOUT_MS: 1e4,
82
+ SIZE_THRESHOLDS: {
83
+ WARNING: 30000,
84
+ CRITICAL: 45000
85
+ },
86
+ COMMON_ARIA_PROPERTIES: [
87
+ "aria-label",
88
+ "aria-describedby",
89
+ "aria-hidden",
90
+ "aria-expanded",
91
+ "aria-selected",
92
+ "aria-checked",
93
+ "aria-disabled",
94
+ "aria-required"
95
+ ]
96
+ };
97
+ export {
98
+ validateHTMLInspectionOptions,
99
+ truncateHtml,
100
+ htmlInspectionOptionsSchema,
101
+ generateHTMLInspectionSuggestions,
102
+ calculateHtmlSize,
103
+ HTMLInspectionUtils,
104
+ HTMLInspectionError,
105
+ HTMLInspectionConstants
106
+ };
@@ -0,0 +1,126 @@
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/types/selectors.ts
21
+ import { z } from "zod";
22
+ var refSelectorSchema = z.object({
23
+ ref: z.string().describe("System-generated element ID from previous tool results")
24
+ });
25
+ var roleSelectorSchema = z.object({
26
+ role: z.string().describe("ARIA role to match (e.g., button, textbox, link)"),
27
+ text: z.string().optional().describe("Optional text content to match within the role")
28
+ });
29
+ var cssSelectorSchema = z.object({
30
+ css: z.string().describe('CSS selector string (e.g., "#id", ".class", "button[type=submit]")')
31
+ });
32
+ var textSelectorSchema = z.object({
33
+ text: z.string().describe("Text content to search for"),
34
+ tag: z.string().optional().describe("Optional HTML tag to limit search scope")
35
+ });
36
+ var elementSelectorSchema = z.union([
37
+ refSelectorSchema,
38
+ roleSelectorSchema,
39
+ cssSelectorSchema,
40
+ textSelectorSchema
41
+ ]).describe("Element selector supporting ref, role, CSS, or text-based selection");
42
+ var SelectorConfidence = {
43
+ HIGH: 0.9,
44
+ MEDIUM: 0.7,
45
+ LOW: 0.5,
46
+ VERY_LOW: 0.3
47
+ };
48
+ var ResolutionStrategy = {
49
+ REF: "ref",
50
+ CSS_PARALLEL: "css_parallel",
51
+ ROLE_SEQUENTIAL: "role_sequential",
52
+ TEXT_FALLBACK: "text_fallback"
53
+ };
54
+ function isRefSelector(selector) {
55
+ return "ref" in selector;
56
+ }
57
+ function isRoleSelector(selector) {
58
+ return "role" in selector;
59
+ }
60
+ function isCSSSelector(selector) {
61
+ return "css" in selector;
62
+ }
63
+ function isTextSelector(selector) {
64
+ return "text" in selector && !("role" in selector);
65
+ }
66
+ function validateElementSelector(selector) {
67
+ return elementSelectorSchema.parse(selector);
68
+ }
69
+ function isValidSelector(selector) {
70
+ try {
71
+ elementSelectorSchema.parse(selector);
72
+ return true;
73
+ } catch {
74
+ return false;
75
+ }
76
+ }
77
+ var SelectorValidator = {
78
+ validateElementSelector,
79
+ isValidSelector
80
+ };
81
+ var SelectorPatterns = {
82
+ ARIA_ROLES: [
83
+ "button",
84
+ "textbox",
85
+ "link",
86
+ "checkbox",
87
+ "radio",
88
+ "combobox",
89
+ "listbox",
90
+ "option",
91
+ "tab",
92
+ "tabpanel",
93
+ "dialog",
94
+ "alert",
95
+ "menu",
96
+ "menuitem",
97
+ "table",
98
+ "row",
99
+ "cell",
100
+ "heading"
101
+ ],
102
+ CSS_PATTERNS: {
103
+ byId: (id) => `#${id}`,
104
+ byClass: (className) => `.${className}`,
105
+ byAttribute: (attr, value) => value ? `[${attr}="${value}"]` : `[${attr}]`,
106
+ byDataTestId: (testId) => `[data-testid="${testId}"]`,
107
+ byRole: (role) => `[role="${role}"]`
108
+ }
109
+ };
110
+ export {
111
+ validateElementSelector,
112
+ textSelectorSchema,
113
+ roleSelectorSchema,
114
+ refSelectorSchema,
115
+ isValidSelector,
116
+ isTextSelector,
117
+ isRoleSelector,
118
+ isRefSelector,
119
+ isCSSSelector,
120
+ elementSelectorSchema,
121
+ cssSelectorSchema,
122
+ SelectorValidator,
123
+ SelectorPatterns,
124
+ SelectorConfidence,
125
+ ResolutionStrategy
126
+ };