* Plain-object snapshot of the element — text, simplified HTML, visibility, * enabled state, and a curated set of attributes. Each underlying call is * isolated so a single failure (e.g. detached element) doesn't poison the * rest. Suitable for JSON.stringify, log output, MCP tool responses
({ maxHtmlLength = 300, attrs = ['id', 'class', 'name', 'role', 'type', 'href', 'value', 'aria-label', 'placeholder', 'data-testid'] } = {})
| 528 | * @returns {Promise<{text?: string, html?: string, visible?: boolean, enabled?: boolean, attrs?: object}>} |
| 529 | */ |
| 530 | async describe({ maxHtmlLength = 300, attrs = ['id', 'class', 'name', 'role', 'type', 'href', 'value', 'aria-label', 'placeholder', 'data-testid'] } = {}) { |
| 531 | const out = {} |
| 532 | await Promise.all([ |
| 533 | this.toSimplifiedHTML(maxHtmlLength).then(v => { if (v) out.html = v }, () => {}), |
| 534 | this.getText().then(v => { const t = v?.trim(); if (t) out.text = t }, () => {}), |
| 535 | this.isVisible().then(v => { out.visible = v }, () => {}), |
| 536 | this.isEnabled().then(v => { out.enabled = v }, () => {}), |
| 537 | ]) |
| 538 | const collected = {} |
| 539 | await Promise.all(attrs.map(async name => { |
| 540 | try { |
| 541 | const v = await this.getAttribute(name) |
| 542 | if (v != null && v !== '') collected[name] = v |
| 543 | } catch {} |
| 544 | })) |
| 545 | if (Object.keys(collected).length) out.attrs = collected |
| 546 | return out |
| 547 | } |
| 548 | |
| 549 | // Make accidental JSON.stringify (e.g. returning a WebElement from MCP run_code) |
| 550 | // produce a usable hint instead of `{}` — the underlying handle isn't |
no test coverage detected