appium-mcp 1.98.0 → 1.99.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +30 -0
  3. package/dist/locators/element-filter.d.ts +3 -1
  4. package/dist/locators/element-filter.d.ts.map +1 -1
  5. package/dist/locators/element-filter.js +44 -14
  6. package/dist/locators/element-filter.js.map +1 -1
  7. package/dist/locators/generate-all-locators.d.ts +6 -1
  8. package/dist/locators/generate-all-locators.d.ts.map +1 -1
  9. package/dist/locators/generate-all-locators.js +1 -1
  10. package/dist/locators/generate-all-locators.js.map +1 -1
  11. package/dist/locators/locator-generation.d.ts +4 -3
  12. package/dist/locators/locator-generation.d.ts.map +1 -1
  13. package/dist/locators/locator-generation.js +31 -10
  14. package/dist/locators/locator-generation.js.map +1 -1
  15. package/dist/locators/types.d.ts +3 -0
  16. package/dist/locators/types.d.ts.map +1 -0
  17. package/dist/locators/types.js +2 -0
  18. package/dist/locators/types.js.map +1 -0
  19. package/dist/tools/gestures/schema.d.ts.map +1 -1
  20. package/dist/tools/gestures/schema.js +7 -15
  21. package/dist/tools/gestures/schema.js.map +1 -1
  22. package/dist/tools/test-generation/locators.d.ts.map +1 -1
  23. package/dist/tools/test-generation/locators.js +19 -5
  24. package/dist/tools/test-generation/locators.js.map +1 -1
  25. package/dist/ui/inspector-screenshot-script.d.ts +3 -0
  26. package/dist/ui/inspector-screenshot-script.d.ts.map +1 -0
  27. package/dist/ui/inspector-screenshot-script.js +164 -0
  28. package/dist/ui/inspector-screenshot-script.js.map +1 -0
  29. package/dist/ui/mcp-ui-utils.d.ts.map +1 -1
  30. package/dist/ui/mcp-ui-utils.js +14 -73
  31. package/dist/ui/mcp-ui-utils.js.map +1 -1
  32. package/dist/ui/page-source-inspector-app.d.ts.map +1 -1
  33. package/dist/ui/page-source-inspector-app.js +79 -75
  34. package/dist/ui/page-source-inspector-app.js.map +1 -1
  35. package/dist/ui/xml-inspector-scripts.d.ts +4 -0
  36. package/dist/ui/xml-inspector-scripts.d.ts.map +1 -0
  37. package/dist/ui/xml-inspector-scripts.js +91 -0
  38. package/dist/ui/xml-inspector-scripts.js.map +1 -0
  39. package/package.json +1 -1
  40. package/server.json +2 -2
  41. package/src/locators/element-filter.ts +50 -16
  42. package/src/locators/generate-all-locators.ts +13 -7
  43. package/src/locators/locator-generation.ts +43 -10
  44. package/src/locators/types.ts +2 -0
  45. package/src/tools/gestures/schema.ts +7 -17
  46. package/src/tools/test-generation/locators.ts +31 -7
  47. package/src/ui/inspector-screenshot-script.ts +163 -0
  48. package/src/ui/mcp-ui-utils.ts +15 -73
  49. package/src/ui/page-source-inspector-app.ts +80 -75
  50. package/src/ui/xml-inspector-scripts.ts +91 -0
@@ -0,0 +1,164 @@
1
+ /** Browser controller for the optional screenshot and XML bounds overlay. */
2
+ export const INSPECTOR_SCREENSHOT_SCRIPT = String.raw `
3
+ function createScreenshotInspector(callTool, setSource, readSourceResult) {
4
+ const button = document.getElementById('takeScreenshotButton');
5
+ const panel = document.getElementById('screenshotPanel');
6
+ const image = document.getElementById('inspectorScreenshot');
7
+ const overlay = document.getElementById('elementOverlay');
8
+ const select = document.getElementById('screenshotElement');
9
+ const status = document.getElementById('screenshotStatus');
10
+ const details = document.getElementById('selectedXmlElement');
11
+ let elements = [];
12
+ let screen;
13
+ let query = '';
14
+
15
+ function readBounds(element) {
16
+ // Drivers differ in attribute casing. Prefer the exact lowercase spelling if both exist.
17
+ function attribute(name) {
18
+ if (element.hasAttribute(name)) return element.getAttribute(name);
19
+ return Array.from(element.attributes).find(attr => attr.name.toLowerCase() === name)?.value;
20
+ }
21
+ const android = (attribute('bounds') || '').match(/^\[(-?\d+),(-?\d+)\]\[(-?\d+),(-?\d+)\]$/);
22
+ if (android) {
23
+ const [, x, y, right, bottom] = android.map(Number);
24
+ return {x, y, width: right - x, height: bottom - y};
25
+ }
26
+ const coordinates = ['x', 'y', 'width', 'height'].map(attribute);
27
+ if (!coordinates.every(value => value !== undefined && value.trim() !== '')) return;
28
+ const values = coordinates.map(Number);
29
+ if (!values.every(Number.isFinite)) return;
30
+ const [x, y, width, height] = values;
31
+ return {x, y, width, height};
32
+ }
33
+
34
+ function showSelection() {
35
+ overlay.hidden = true;
36
+ details.textContent = '';
37
+ if (!select.value) return;
38
+ const element = elements[Number(select.value) - 1];
39
+ if (!element) return;
40
+ // Display only the selected opening tag, not its entire subtree.
41
+ const clone = element.cloneNode(false);
42
+ details.textContent = new XMLSerializer().serializeToString(clone);
43
+ if (!screen) {
44
+ status.textContent = 'Take a screenshot to highlight this element.';
45
+ return;
46
+ }
47
+ const rect = readBounds(element);
48
+ if (!rect || rect.width <= 0 || rect.height <= 0) {
49
+ status.textContent = 'This element has no usable screen bounds.';
50
+ return;
51
+ }
52
+ if (element.getAttribute('visible') === 'false' || element.getAttribute('displayed') === 'false') {
53
+ status.textContent = 'This element is marked hidden in the XML.';
54
+ return;
55
+ }
56
+ const left = Math.max(0, rect.x);
57
+ const top = Math.max(0, rect.y);
58
+ const right = Math.min(screen.width, rect.x + rect.width);
59
+ const bottom = Math.min(screen.height, rect.y + rect.height);
60
+ if (right <= left || bottom <= top) {
61
+ status.textContent = 'This element is outside the captured screen.';
62
+ return;
63
+ }
64
+ overlay.style.left = (left / screen.width * 100) + '%';
65
+ overlay.style.top = (top / screen.height * 100) + '%';
66
+ overlay.style.width = ((right - left) / screen.width * 100) + '%';
67
+ overlay.style.height = ((bottom - top) / screen.height * 100) + '%';
68
+ overlay.hidden = false;
69
+ status.textContent = 'XML bounds: x=' + rect.x + ', y=' + rect.y + ', width=' + rect.width + ', height=' + rect.height;
70
+ }
71
+
72
+ function filter(nextQuery) {
73
+ query = nextQuery.trim().toLowerCase();
74
+ const previous = select.value;
75
+ select.textContent = '';
76
+ const placeholder = document.createElement('option');
77
+ placeholder.value = '';
78
+ placeholder.textContent = 'Select an XML element to highlight';
79
+ select.appendChild(placeholder);
80
+ let retained = false;
81
+ elements.forEach((element, index) => {
82
+ const attributes = Array.from(element.attributes).map(attr => attr.value);
83
+ if (query && ![element.tagName, ...attributes].some(value => value.toLowerCase().includes(query))) return;
84
+ const option = document.createElement('option');
85
+ option.value = String(index + 1);
86
+ const name = element.getAttribute('name') || element.getAttribute('label') || element.getAttribute('text') || element.getAttribute('resource-id') || element.getAttribute('id');
87
+ option.textContent = (index + 1) + '. ' + element.tagName + (name ? ' — ' + name : '');
88
+ select.appendChild(option);
89
+ if (option.value === previous) retained = true;
90
+ });
91
+ select.value = retained ? previous : '';
92
+ showSelection();
93
+ }
94
+
95
+ function updateSource(source) {
96
+ screen = undefined;
97
+ image.hidden = true;
98
+ overlay.hidden = true;
99
+ elements = [];
100
+ select.value = '';
101
+ if (source.trim().startsWith('<')) {
102
+ const doc = new DOMParser().parseFromString(source, 'text/xml');
103
+ if (!doc.getElementsByTagName('parsererror').length) elements = Array.from(doc.getElementsByTagName('*'));
104
+ }
105
+ filter(query);
106
+ status.textContent = 'XML updated. Take a screenshot to refresh the preview.';
107
+ }
108
+
109
+ function assertSuccess(result) {
110
+ if (result?.isError) throw new Error((result.content || []).filter(item => item.type === 'text').map(item => item.text).join('\n') || 'Tool failed');
111
+ return result;
112
+ }
113
+
114
+ async function capture() {
115
+ if (button.disabled) return;
116
+ button.disabled = true;
117
+ panel.hidden = false;
118
+ screen = undefined;
119
+ image.hidden = true;
120
+ overlay.hidden = true;
121
+ status.textContent = 'Capturing screenshot and refreshing XML…';
122
+ try {
123
+ const sourceResult = assertSuccess(await callTool('appium_get_page_source', {saveToFile: false}));
124
+ const sizeResult = assertSuccess(await callTool('appium_get_window_size', {}));
125
+ const result = assertSuccess(await callTool('appium_screenshot', {returnRawBase64: true}));
126
+ const sizeText = (sizeResult.content || []).filter(item => item.type === 'text').map(item => item.text).join(' ');
127
+ const size = sizeText.match(/Width:\s*([\d.]+),\s*Height:\s*([\d.]+)/);
128
+ if (!size || !(Number(size[1]) > 0 && Number(size[2]) > 0)) throw new Error('Screen size is unavailable');
129
+ const picture = result.structuredContent?.screenshot || (result.content || []).find(item => item.type === 'image');
130
+ if (!picture?.data || !['image/png', 'image/jpeg'].includes(picture.mimeType)) throw new Error('No supported screenshot returned');
131
+ setSource(readSourceResult(sourceResult));
132
+ screen = {width: Number(size[1]), height: Number(size[2])};
133
+ image.src = 'data:' + picture.mimeType + ';base64,' + picture.data;
134
+ image.hidden = false;
135
+ status.textContent = 'Select an XML element below. Search filters the list.';
136
+ } catch (error) {
137
+ status.textContent = 'Screenshot failed: ' + error.message;
138
+ } finally {
139
+ button.disabled = false;
140
+ }
141
+ }
142
+
143
+ image.addEventListener('load', () => {
144
+ if (!screen) return;
145
+ // Pixel density is handled by percentages; orientation changes are not.
146
+ const ratio = image.naturalWidth / image.naturalHeight;
147
+ if (Math.abs(ratio / (screen.width / screen.height) - 1) > 0.03) {
148
+ screen = undefined;
149
+ overlay.hidden = true;
150
+ status.textContent = 'Screenshot and screen dimensions differ. Capture again before highlighting.';
151
+ }
152
+ });
153
+ image.addEventListener('error', () => {
154
+ screen = undefined;
155
+ image.hidden = true;
156
+ overlay.hidden = true;
157
+ status.textContent = 'Unable to display screenshot.';
158
+ });
159
+ button.addEventListener('click', capture);
160
+ select.addEventListener('change', showSelection);
161
+ return {updateSource, filter};
162
+ }
163
+ `;
164
+ //# sourceMappingURL=inspector-screenshot-script.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspector-screenshot-script.js","sourceRoot":"","sources":["../../src/ui/inspector-screenshot-script.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;C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,CAAC;CACpB,CAAC,GACD,MAAM,CAmMR;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAiLtE;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAgKjG;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC,GAAG,MAAM,CAgN5F;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAe,GAAG,MAAM,CAyJtF;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE;IAAC,OAAO,EAAE,KAAK,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC,CAAA;CAAC,EACzD,UAAU,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,GAAG,CAAC,MAAM,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC,GAC5F;IAAC,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;CAAC,CAUvB"}
@@ -1,3 +1,4 @@
1
+ import { XML_FORMAT_SCRIPT, XML_SEARCH_SCRIPT } from './xml-inspector-scripts.js';
1
2
  /**
2
3
  * MCP-UI Utility Functions
3
4
  *
@@ -959,6 +960,10 @@ export function createPageSourceInspectorUI(pageSource) {
959
960
  outline: none;
960
961
  border-color: #007AFF;
961
962
  }
963
+ mark { background: #ffd700; color: #000; }
964
+ mark[data-active] { outline: 2px solid #91baff; background: #ff963c; }
965
+ .search-status { padding: 6px 16px; font-size: 12px; color: #bbb; }
966
+ .search-status:empty { display: none; }
962
967
  </style>
963
968
  </head>
964
969
  <body>
@@ -975,11 +980,14 @@ export function createPageSourceInspectorUI(pageSource) {
975
980
  <button class="btn" onclick="generateLocators()">Generate Locators</button>
976
981
  </div>
977
982
  </div>
983
+ <div id="searchStatus" class="search-status" role="status" aria-live="polite"></div>
978
984
  <div class="viewer" title="Drag the bottom-right corner to resize vertically">
979
985
  <pre class="xml-content" id="xmlContent">${escapedSource}</pre>
980
986
  </div>
981
987
  </details>
982
988
  <script>
989
+ ${XML_FORMAT_SCRIPT}
990
+ ${XML_SEARCH_SCRIPT}
983
991
  function copyToClipboard() {
984
992
  const text = document.getElementById('xmlContent').textContent;
985
993
  navigator.clipboard.writeText(text).then(() => {
@@ -989,44 +997,7 @@ export function createPageSourceInspectorUI(pageSource) {
989
997
 
990
998
  function formatXML() {
991
999
  try {
992
- const parser = new DOMParser();
993
- const xmlDoc = parser.parseFromString(originalSource, 'text/xml');
994
- if (!xmlDoc.documentElement || xmlDoc.getElementsByTagName('parsererror').length) {
995
- throw new Error('Invalid XML');
996
- }
997
-
998
- function indentElement(element, depth) {
999
- // Do not introduce whitespace into mixed content or preserved subtrees.
1000
- if (element.getAttribute('xml:space') === 'preserve') return;
1001
- const children = Array.from(element.childNodes);
1002
- if (children.some(child =>
1003
- child.nodeType === 4 || (child.nodeType === 3 && child.nodeValue.trim())
1004
- )) return;
1005
- if (!children.some(child => child.nodeType === 1)) return;
1006
-
1007
- for (const child of children) {
1008
- if (child.nodeType === 3) {
1009
- element.removeChild(child);
1010
- continue;
1011
- }
1012
- if (child.nodeType === 1) indentElement(child, depth + 1);
1013
- element.insertBefore(xmlDoc.createTextNode('\\n' + ' '.repeat(depth + 1)), child);
1014
- }
1015
- element.appendChild(xmlDoc.createTextNode('\\n' + ' '.repeat(depth)));
1016
- }
1017
-
1018
- indentElement(xmlDoc.documentElement, 0);
1019
- const serializer = new XMLSerializer();
1020
- let formatted = Array.from(xmlDoc.childNodes)
1021
- .filter(node => node.nodeType !== 3)
1022
- .map(node => serializer.serializeToString(node))
1023
- .join('\\n');
1024
- // Browser DOMParser does not retain the XML declaration.
1025
- const declaration = originalSource.match(/^\\s*(<\\?xml\\s[^?]*\\?>)/);
1026
- if (declaration && !formatted.startsWith('<?xml ')) {
1027
- formatted = declaration[1] + '\\n' + formatted;
1028
- }
1029
- displayedSource = formatted;
1000
+ displayedSource = formatXml(originalSource);
1030
1001
  renderSource(document.getElementById('searchBox').value);
1031
1002
  } catch (e) {
1032
1003
  alert('Failed to format XML');
@@ -1038,7 +1009,7 @@ export function createPageSourceInspectorUI(pageSource) {
1038
1009
  type: 'tool',
1039
1010
  payload: {
1040
1011
  toolName: 'generate_locators',
1041
- params: {}
1012
+ params: {query: document.getElementById('searchBox').value.trim()}
1042
1013
  }
1043
1014
  }, '*');
1044
1015
  }
@@ -1047,42 +1018,12 @@ export function createPageSourceInspectorUI(pageSource) {
1047
1018
  const originalSource = xmlContent.textContent;
1048
1019
  let displayedSource = originalSource;
1049
1020
 
1050
- function appendTextWithHighlights(container, text, searchTerm) {
1051
- const searchLower = searchTerm.toLowerCase();
1052
- const textLower = text.toLowerCase();
1053
- let position = 0;
1054
-
1055
- while (position < text.length) {
1056
- const matchIndex = textLower.indexOf(searchLower, position);
1057
- if (matchIndex === -1) {
1058
- container.appendChild(document.createTextNode(text.slice(position)));
1059
- return;
1060
- }
1061
-
1062
- if (matchIndex > position) {
1063
- container.appendChild(
1064
- document.createTextNode(text.slice(position, matchIndex))
1065
- );
1066
- }
1067
-
1068
- const mark = document.createElement('mark');
1069
- mark.style.background = '#ffd700';
1070
- mark.style.color = '#000';
1071
- mark.textContent = text.slice(matchIndex, matchIndex + searchTerm.length);
1072
- container.appendChild(mark);
1073
- position = matchIndex + searchTerm.length;
1074
- }
1075
- }
1076
-
1021
+ const searchBox = document.getElementById('searchBox');
1022
+ const xmlSearch = createXmlSearch(xmlContent, document.getElementById('searchStatus'));
1077
1023
  function renderSource(searchTerm = '') {
1078
- xmlContent.textContent = '';
1079
- if (!searchTerm) {
1080
- xmlContent.textContent = displayedSource;
1081
- return;
1082
- }
1083
-
1084
- appendTextWithHighlights(xmlContent, displayedSource, searchTerm);
1024
+ xmlSearch.render(displayedSource, searchTerm);
1085
1025
  }
1026
+ searchBox.addEventListener('keydown', xmlSearch.handleKeyDown);
1086
1027
 
1087
1028
  // Search functionality
1088
1029
  document.getElementById('searchBox').addEventListener('input', (e) => {
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-ui-utils.js","sourceRoot":"","sources":["../../src/ui/mcp-ui-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAW,EACX,WAAmB;IASnB,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE;YACR,GAAG;YACH,QAAQ,EAAE,WAAW;YACrB,IAAI,EAAE,WAAW;SAClB;KACF,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAKE,EACF,QAA2B,EAC3B,UAAiC;IAEjC,MAAM,eAAe,GACnB,QAAQ,KAAK,KAAK,IAAI,UAAU;QAC9B,CAAC,CAAC,UAAU,KAAK,WAAW;YAC1B,CAAC,CAAC,gBAAgB;YAClB,CAAC,CAAC,aAAa;QACjB,CAAC,CAAC,iBAAiB,CAAC;IAExB,MAAM,WAAW,GAAG,OAAO;SACxB,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QACrB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACjC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC;QACjC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MA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C,UAAU,EAAE,EAAE,CAAC,CAC3B,CAAC;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"page-source-inspector-app.d.ts","sourceRoot":"","sources":["../../src/ui/page-source-inspector-app.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,8BAA8B,IAAI,MAAM,CAsVvD"}
1
+ {"version":3,"file":"page-source-inspector-app.d.ts","sourceRoot":"","sources":["../../src/ui/page-source-inspector-app.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,8BAA8B,IAAI,MAAM,CAwVvD"}
@@ -1,3 +1,5 @@
1
+ import { INSPECTOR_SCREENSHOT_SCRIPT } from './inspector-screenshot-script.js';
2
+ import { XML_FORMAT_SCRIPT, XML_SEARCH_SCRIPT } from './xml-inspector-scripts.js';
1
3
  /**
2
4
  * Static MCP App used by appium_get_page_source.
3
5
  *
@@ -35,10 +37,19 @@ export function createPageSourceInspectorAppUI() {
35
37
  .viewer { height: 320px; min-height: 160px; resize: vertical; overflow: auto; padding: 20px; }
36
38
  .xml-content, .selector { margin: 0; font: 12px/1.75 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
37
39
  .xml-content { white-space: pre; color: #c5d3e7; }
40
+ mark[data-active] { outline: 2px solid #91baff; background: #ff963c; }
41
+ .search-status { padding: 6px 20px; color: var(--muted); font-size: 12px; }
42
+ .search-status:empty { display: none; }
38
43
  mark { border-radius: 3px; background: #eac77a; color: #252019; }
39
44
  .empty, .hint { color: var(--muted); }
40
45
  .empty { font-family: inherit; }
41
46
  .hint { margin: 6px 0 0; font-size: 12px; }
47
+ .screenshot-panel { border-top: 1px solid var(--line); padding: 20px; }
48
+ .screenshot-frame { position: relative; width: fit-content; max-width: 100%; margin: 12px auto; }
49
+ .screenshot-frame img { display: block; max-width: 100%; max-height: 480px; }
50
+ .element-overlay { position: absolute; border: 2px solid #ff963c; background: #ff963c33; pointer-events: none; }
51
+ #screenshotElement { width: 100%; margin: 10px 0; padding: 8px; background: var(--panel); color: var(--text); border: 1px solid var(--line); }
52
+ #selectedXmlElement { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }
42
53
  .locators { border-top: 1px solid var(--line); padding: 20px; }
43
54
  h2 { margin: 0; font-size: 14px; font-weight: 600; }
44
55
  #locatorStatus { margin: 16px 0 10px; color: var(--accent); font-size: 12px; }
@@ -59,21 +70,38 @@ export function createPageSourceInspectorAppUI() {
59
70
  <span class="info" id="sourceInfo">Waiting for page source…</span>
60
71
  </summary>
61
72
  <div class="toolbar">
62
- <input type="search" class="search-box" id="searchBox" placeholder="Find in XML…" aria-label="Find in XML" title="Highlight matching text in the XML">
73
+ <input type="search" class="search-box" id="searchBox" placeholder="Search elements…" aria-label="Search elements" title="Highlight XML text and find locator candidates by element tag or attribute value">
63
74
  <div class="toolbar-right">
75
+ <button class="btn btn-secondary" id="takeScreenshotButton">Take screenshot</button>
64
76
  <button class="btn btn-secondary" id="formatButton">Format XML</button>
65
77
  <button class="btn btn-secondary" id="copyButton">Copy XML</button>
66
78
  </div>
67
79
  </div>
80
+ <div id="searchStatus" class="search-status" role="status" aria-live="polite"></div>
68
81
  <div class="viewer" title="Drag the bottom-right corner to resize vertically">
69
82
  <pre class="xml-content empty" id="xmlContent">Waiting for page source…</pre>
70
83
  </div>
84
+ <section id="screenshotPanel" class="screenshot-panel" hidden aria-label="Screenshot preview">
85
+ <h2>Screenshot &amp; XML elements</h2>
86
+ <p class="hint">Capture refreshes XML too. Select an element to overlay its bounds. Images and XML are captured sequentially; keep the screen still. Supports x/y/width/height and Android bounds.</p>
87
+ <p id="screenshotStatus" role="status" aria-live="polite"></p>
88
+ <div class="screenshot-frame">
89
+ <img id="inspectorScreenshot" alt="Device screenshot" hidden>
90
+ <div id="elementOverlay" class="element-overlay" hidden></div>
91
+ </div>
92
+ <label for="screenshotElement">XML element (filtered by Search)</label>
93
+ <select id="screenshotElement"><option value="">Select an XML element to highlight</option></select>
94
+ <pre id="selectedXmlElement"></pre>
95
+ </section>
71
96
  <section class="locators" aria-labelledby="locatorsHeading">
72
97
  <div class="section-header">
73
98
  <h2 id="locatorsHeading">Locator candidates</h2>
74
- <button class="btn" id="generateButton">Generate from current page</button>
99
+ <button class="btn" id="generateButton">Find locators</button>
75
100
  </div>
76
- <p class="hint">Fetches fresh XML from the device and generates candidates for supported element types, including hidden elements. XML search only highlights text above.</p>
101
+ <p class="hint">Find locators for elements matching the search text in their type or attributes (name, label, text, ID, etc.). Matches ignore case and may include hidden elements. Fetches fresh XML; leave search blank for the default candidate list.</p>
102
+ <label class="hint" for="xpathAttributes">Preferred XPath attributes (optional)</label>
103
+ <input type="text" class="search-box" id="xpathAttributes" placeholder="AutomationId, data-testid" aria-describedby="xpathAttributesHelp" style="display:block;width:100%;margin-top:6px">
104
+ <p class="hint" id="xpathAttributesHelp">Comma-separated attribute names, in priority order. Existing attributes remain as fallback.</p>
77
105
  <div id="locatorResults" hidden>
78
106
  <p id="locatorStatus" role="status" aria-live="polite"></p>
79
107
  <div class="locator-results" id="locatorOutput"></div>
@@ -82,6 +110,9 @@ export function createPageSourceInspectorAppUI() {
82
110
  </details>
83
111
  <script>
84
112
  (() => {
113
+ ${XML_FORMAT_SCRIPT}
114
+ ${XML_SEARCH_SCRIPT}
115
+ ${INSPECTOR_SCREENSHOT_SCRIPT}
85
116
  const PAGE_SOURCE_PREFIX = 'Page source retrieved successfully: \\n\\\`\\\`\\\`xml ';
86
117
  const xmlContent = document.getElementById('xmlContent');
87
118
  const sourceInfo = document.getElementById('sourceInfo');
@@ -90,11 +121,16 @@ export function createPageSourceInspectorAppUI() {
90
121
  const locatorResults = document.getElementById('locatorResults');
91
122
  const locatorStatus = document.getElementById('locatorStatus');
92
123
  const locatorOutput = document.getElementById('locatorOutput');
124
+ const xmlSearch = createXmlSearch(xmlContent, document.getElementById('searchStatus'));
93
125
  let source = '';
94
126
  let savedFile;
95
127
  let nextRequestId = 1;
96
128
  const pendingRequests = new Map();
97
129
 
130
+ const screenshotInspector = createScreenshotInspector(
131
+ (name, args) => sendRequest('tools/call', {name, arguments: args}), setSource, sourceFromToolResult,
132
+ );
133
+
98
134
  function sendRequest(method, params) {
99
135
  const id = nextRequestId++;
100
136
  window.parent.postMessage({jsonrpc: '2.0', id, method, params}, '*');
@@ -128,30 +164,9 @@ export function createPageSourceInspectorAppUI() {
128
164
  return text;
129
165
  }
130
166
 
131
- function appendHighlightedText(container, text, query) {
132
- const lowerText = text.toLowerCase();
133
- const lowerQuery = query.toLowerCase();
134
- let position = 0;
135
-
136
- while (position < text.length) {
137
- const matchIndex = lowerText.indexOf(lowerQuery, position);
138
- if (matchIndex === -1) {
139
- container.appendChild(document.createTextNode(text.slice(position)));
140
- return;
141
- }
142
- if (matchIndex > position) {
143
- container.appendChild(document.createTextNode(text.slice(position, matchIndex)));
144
- }
145
- const mark = document.createElement('mark');
146
- mark.textContent = text.slice(matchIndex, matchIndex + query.length);
147
- container.appendChild(mark);
148
- position = matchIndex + query.length;
149
- }
150
- }
151
-
152
167
  function renderSource() {
153
168
  const query = searchBox.value.trim();
154
- xmlContent.textContent = '';
169
+ xmlSearch.render('', '');
155
170
  xmlContent.classList.toggle('empty', source.length === 0);
156
171
  if (savedFile) {
157
172
  sourceInfo.textContent = savedFile.bytes + ' bytes saved';
@@ -160,59 +175,22 @@ export function createPageSourceInspectorAppUI() {
160
175
  }
161
176
  if (!source) {
162
177
  xmlContent.textContent = 'No page source was returned.';
163
- } else if (!query) {
164
- xmlContent.textContent = source;
165
178
  } else {
166
- appendHighlightedText(xmlContent, source, query);
179
+ xmlSearch.render(source, query);
167
180
  }
168
181
  sourceInfo.textContent = source.length + ' characters';
169
182
  }
170
183
 
171
184
  function setSource(nextSource) {
172
185
  source = nextSource;
186
+ screenshotInspector.updateSource(source);
173
187
  renderSource();
174
188
  }
175
189
 
176
190
  function formatXML() {
177
191
  if (!source) return;
178
192
  try {
179
- const parser = new DOMParser();
180
- const documentNode = parser.parseFromString(source, 'text/xml');
181
- if (!documentNode.documentElement || documentNode.getElementsByTagName('parsererror').length) {
182
- throw new Error('Invalid XML');
183
- }
184
-
185
- function indentElement(element, depth) {
186
- if (element.getAttribute('xml:space') === 'preserve') return;
187
- const children = Array.from(element.childNodes);
188
- const hasMixedContent = children.some((child) =>
189
- child.nodeType === 4 || (child.nodeType === 3 && (child.nodeValue || '').trim()),
190
- );
191
- if (hasMixedContent || !children.some((child) => child.nodeType === 1)) return;
192
-
193
- for (const child of children) {
194
- if (child.nodeType === 3) {
195
- element.removeChild(child);
196
- continue;
197
- }
198
- if (child.nodeType === 1) indentElement(child, depth + 1);
199
- element.insertBefore(documentNode.createTextNode('\\n' + ' '.repeat(depth + 1)), child);
200
- }
201
- element.appendChild(documentNode.createTextNode('\\n' + ' '.repeat(depth)));
202
- }
203
-
204
- indentElement(documentNode.documentElement, 0);
205
- const serializer = new XMLSerializer();
206
- let formattedSource = Array.from(documentNode.childNodes)
207
- .filter((node) => node.nodeType !== 3)
208
- .map((node) => serializer.serializeToString(node))
209
- .join('\\n');
210
- const declaration = source.match(/^\\s*(<\\?xml\\s[^?]*\\?>)/);
211
- if (declaration && !formattedSource.startsWith('<?xml ')) {
212
- formattedSource = declaration[1] + '\\n' + formattedSource;
213
- }
214
-
215
- source = formattedSource;
193
+ source = formatXml(source);
216
194
  renderSource();
217
195
  } catch {
218
196
  window.alert('Failed to format XML');
@@ -268,22 +246,44 @@ export function createPageSourceInspectorAppUI() {
268
246
  });
269
247
  }
270
248
 
249
+ function parseLocatorResult(result) {
250
+ const text = (result?.content || [])
251
+ .filter(item => item.type === 'text')
252
+ .map(item => item.text)
253
+ .join('\\n');
254
+ if (result?.isError) throw new Error(text || 'Tool returned an error');
255
+ const data = JSON.parse(text);
256
+ if (!Array.isArray(data.interactableElements)) throw new Error('No locator data returned');
257
+ return data.interactableElements;
258
+ }
259
+
260
+ function describeLocatorResults(count, query) {
261
+ if (query) {
262
+ const matches = count ? count + ' matching elements' : 'No matching elements';
263
+ return matches + ' for “' + query + '” in freshly fetched XML.';
264
+ }
265
+ if (!count) return 'No supported elements found in the fetched XML.';
266
+ return 'Candidates generated for ' + count + ' elements from freshly fetched XML.';
267
+ }
268
+
271
269
  async function generateLocators() {
272
270
  if (generateButton.disabled) return;
271
+ const query = searchBox.value.trim();
273
272
  generateButton.disabled = true;
274
273
  locatorResults.hidden = false;
275
274
  locatorStatus.textContent = 'Fetching XML and generating candidates…';
276
275
  locatorOutput.textContent = '';
277
276
  try {
278
- const result = await sendRequest('tools/call', {name: 'generate_locators', arguments: {}});
279
- const text = (result?.content || []).filter((item) => item.type === 'text').map((item) => item.text).join('\\n');
280
- if (result?.isError) throw new Error(text || 'Tool returned an error');
281
- const data = JSON.parse(text);
282
- if (!Array.isArray(data.interactableElements)) throw new Error('No locator data returned');
283
- const elements = data.interactableElements;
284
- locatorStatus.textContent = elements.length
285
- ? 'Candidates generated for ' + elements.length + ' elements from freshly fetched XML.'
286
- : 'No supported elements found in the fetched XML.';
277
+ const xpathAttributes = [...new Set((document.getElementById('xpathAttributes').value || '')
278
+ .split(',').map(name => name.trim()).filter(Boolean))];
279
+ if (xpathAttributes.length > 20 || xpathAttributes.some(name => !/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(name))) {
280
+ throw new Error('Enter up to 20 attribute names, separated by commas (no XPath expressions or namespace prefixes).');
281
+ }
282
+ const args = query ? {query} : {};
283
+ if (xpathAttributes.length) args.xpathAttributes = xpathAttributes;
284
+ const result = await sendRequest('tools/call', {name: 'generate_locators', arguments: args});
285
+ const elements = parseLocatorResult(result);
286
+ locatorStatus.textContent = describeLocatorResults(elements.length, query);
287
287
  renderLocators(elements);
288
288
  } catch (error) {
289
289
  locatorStatus.textContent = 'Failed to generate locators: ' + error.message;
@@ -313,7 +313,11 @@ export function createPageSourceInspectorAppUI() {
313
313
  }
314
314
  });
315
315
 
316
- searchBox.addEventListener('input', renderSource);
316
+ searchBox.addEventListener('input', () => {
317
+ renderSource();
318
+ screenshotInspector.filter(searchBox.value);
319
+ });
320
+ searchBox.addEventListener('keydown', xmlSearch.handleKeyDown);
317
321
  document.getElementById('copyButton').addEventListener('click', copyToClipboard);
318
322
  document.getElementById('formatButton').addEventListener('click', formatXML);
319
323
  document.getElementById('generateButton').addEventListener('click', generateLocators);
@@ -1 +1 @@
1
- {"version":3,"file":"page-source-inspector-app.js","sourceRoot":"","sources":["../../src/ui/page-source-inspector-app.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B;IAC5C,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoVN,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"page-source-inspector-app.js","sourceRoot":"","sources":["../../src/ui/page-source-inspector-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,2BAA2B,EAAC,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAC,iBAAiB,EAAE,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAEhF;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B;IAC5C,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAuGD,iBAAiB;QACjB,iBAAiB;QACjB,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6OhC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ /** Shared browser helpers embedded by both inspector transports. Keep these scripts data-free. */
2
+ export declare const XML_FORMAT_SCRIPT: string;
3
+ export declare const XML_SEARCH_SCRIPT: string;
4
+ //# sourceMappingURL=xml-inspector-scripts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xml-inspector-scripts.d.ts","sourceRoot":"","sources":["../../src/ui/xml-inspector-scripts.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,eAAO,MAAM,iBAAiB,QAsC7B,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAiD7B,CAAC"}