@nyx-intelligence/val-mcp 0.5.0 → 0.5.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/dist/index.js CHANGED
@@ -66,7 +66,7 @@ async function runServer() {
66
66
  const { StdioServerTransport } = await import("@modelcontextprotocol/sdk/server/stdio.js");
67
67
  const { chromium } = await import("playwright");
68
68
  const { z } = await import("zod");
69
- const server = new McpServer({ name: "val", version: "0.5.0" });
69
+ const server = new McpServer({ name: "val", version: "0.5.4" });
70
70
  const text = (t) => ({ content: [{ type: "text", text: t }] });
71
71
  // ── Passive crawl ──
72
72
  server.registerTool("val_scan", {
package/dist/session.js CHANGED
@@ -153,9 +153,41 @@ class ValSession {
153
153
  const r = el.getBoundingClientRect();
154
154
  return r.width > 0 && r.height > 0;
155
155
  };
156
- const els = Array.from(document.querySelectorAll("button, [role=button]")).filter(isVisible);
156
+ // Skip buttons that are toggles / segmented-control items / already-active
157
+ // controls — clicking them is a legitimate no-op, not a dead control.
158
+ const TOGGLE_ROLES = ["tab", "switch", "radio", "option", "menuitemradio", "menuitemcheckbox"];
159
+ const CONTAINER_ROLES = ["tablist", "radiogroup", "listbox", "menu", "tabs"];
160
+ const ACTIVE_CLASS = /(^|\s|-)(active|selected|is-active|is-selected|current|is-current)(\s|$|-)/i;
161
+ const isToggleLike = (el) => {
162
+ if (el.hasAttribute("disabled") || el.getAttribute("aria-disabled") === "true")
163
+ return true;
164
+ if (el.hasAttribute("aria-pressed") || el.hasAttribute("aria-selected"))
165
+ return true;
166
+ const ac = el.getAttribute("aria-current");
167
+ if (ac && ac !== "false")
168
+ return true;
169
+ const role = el.getAttribute("role");
170
+ if (role && TOGGLE_ROLES.indexOf(role) >= 0)
171
+ return true;
172
+ if (ACTIVE_CLASS.test(el.getAttribute("class") || ""))
173
+ return true;
174
+ let p = el.parentElement;
175
+ while (p) {
176
+ const r = p.getAttribute("role");
177
+ if (r && CONTAINER_ROLES.indexOf(r) >= 0)
178
+ return true;
179
+ p = p.parentElement;
180
+ }
181
+ return false;
182
+ };
183
+ const els = Array.from(document.querySelectorAll("button, [role=button]"))
184
+ .filter(isVisible)
185
+ .filter((el) => !isToggleLike(el));
157
186
  els.forEach((el, i) => el.setAttribute("data-val-ex", `e${i}`));
158
- return els.map((el, i) => ({ ref: `e${i}`, text: (el.innerText || el.getAttribute("aria-label") || "").trim().slice(0, 40) }));
187
+ return els.map((el, i) => ({
188
+ ref: `e${i}`,
189
+ text: (el.innerText || el.getAttribute("aria-label") || "").trim().slice(0, 40),
190
+ }));
159
191
  });
160
192
  const buttons = await tag();
161
193
  const dead = [];
@@ -163,13 +195,41 @@ class ValSession {
163
195
  const startUrl = page.url();
164
196
  for (const b of buttons) {
165
197
  this.drain();
166
- const before = await this.sig();
167
198
  try {
199
+ const before = await this.sig();
168
200
  const loc = page.locator(`[data-val-ex="${b.ref}"]`);
169
201
  if ((await loc.count()) === 0)
170
202
  continue;
203
+ // Install mutation watcher BEFORE the click. The handler can mutate
204
+ // the DOM synchronously and finish before we start observing — we'd
205
+ // then wait 800ms for nothing and falsely flag the button dead.
206
+ // Watch ANY mutation: node added/removed (modal, dropdown), attribute
207
+ // changed (`value=`, `style`, `aria-*` — React preset buttons), or
208
+ // text changed (counters, totals). Anything = the click did something.
209
+ await page.evaluate(() => {
210
+ const w = window;
211
+ w.__valMut = false;
212
+ const obs = new MutationObserver(() => {
213
+ w.__valMut = true;
214
+ });
215
+ obs.observe(document.body, {
216
+ childList: true,
217
+ subtree: true,
218
+ attributes: true,
219
+ characterData: true,
220
+ });
221
+ w.__valObs = obs;
222
+ });
171
223
  await loc.click({ timeout: 4000 });
172
- await page.waitForTimeout(400);
224
+ await page.waitForTimeout(800);
225
+ const mutated = await page
226
+ .evaluate(() => {
227
+ const w = window;
228
+ const m = !!w.__valMut;
229
+ w.__valObs?.disconnect();
230
+ return m;
231
+ })
232
+ .catch(() => false);
173
233
  if (page.url() !== startUrl) {
174
234
  await page.goBack({ waitUntil: "load" }).catch(() => { });
175
235
  await page.waitForTimeout(300);
@@ -179,14 +239,35 @@ class ValSession {
179
239
  const after = await this.sig();
180
240
  const errs = this.drain();
181
241
  const label = b.text || b.ref;
182
- const moved = after.nodes !== before.nodes || Math.abs(after.text - before.text) > 3;
242
+ const sigChanged = after.nodes !== before.nodes || Math.abs(after.text - before.text) > 3;
243
+ const moved = mutated || sigChanged;
183
244
  if (errs.newPageErrors.length)
184
245
  errored.push({ el: label, error: errs.newPageErrors[0] });
185
246
  else if (!moved && errs.newConsoleErrors.length === 0 && errs.newNetworkErrors.length === 0)
186
247
  dead.push(label);
187
248
  }
188
249
  catch (e) {
189
- errored.push({ el: b.text || b.ref, error: e instanceof Error ? e.message : String(e) });
250
+ const msg = e instanceof Error ? e.message : String(e);
251
+ // SPA navigations can destroy our eval context mid-probe — recover silently,
252
+ // don't flag the click as an error of the page under test.
253
+ if (/Execution context was destroyed|Target closed|frame got detached|Navigation/i.test(msg)) {
254
+ try {
255
+ if (page.url() !== startUrl) {
256
+ await page.goBack({ waitUntil: "load" }).catch(() => { });
257
+ await page.waitForTimeout(300);
258
+ }
259
+ else {
260
+ await page.waitForLoadState("load", { timeout: 2000 }).catch(() => { });
261
+ }
262
+ await tag();
263
+ }
264
+ catch {
265
+ /* nothing more we can do */
266
+ }
267
+ }
268
+ else {
269
+ errored.push({ el: b.text || b.ref, error: msg });
270
+ }
190
271
  }
191
272
  }
192
273
  return { tested: buttons.length, dead, errored };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nyx-intelligence/val-mcp",
3
- "version": "0.5.0",
3
+ "version": "0.5.4",
4
4
  "description": "Val — a 100% MCP QA agent for vibecoders. Drives a real browser to catch UX bugs (broken links, 404s, console errors, broken images) so your coding agent can fix them.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",