execute_script turns string args into elements when they happen to match one element

Aperta
#202 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
50/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
api

Direzione di ricerca

The argument handling is in src/tools/execute-script.tool.ts around lines 40-50, where each string argument is run through $ and swapped for an element when it matches exactly one node. Start there and in the tool's input schema to see how args is defined. Get a maintainer decision on the explicit form (an index list versus { selector } objects) before editing, since the proposal is open and this is a behaviour change. Done means plain strings always pass through unchanged and any deprecation path is documented.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Target: feature/v5 (breaking change, no v4 stopgap).

Problem. execute_script checks every string argument against the page as a selector, and passes an element instead of the string whenever the selector matches exactly one element (src/tools/execute-script.tool.ts:40-55). With WebdriverIO v10's strict $, more than one match throws, which is caught, so the string survives. The result depends on the page, not on what the caller meant:

Call Page The script receives
args: ['main'] one <main> an element
args: ['main'] no <main> the string 'main'
args: ['a'] one link an element
args: ['a'] several links the string 'a'

Words such as main, h1, form, nav, table or #total collide with real pages, so the same tool call behaves differently on different pages. Each candidate also costs a WebDriver round trip.

Proposal. Make it explicit: { selector: '…' } objects in args. Plain strings always stay strings. This is a breaking change, so it ships in v5 with no v4 deprecation path. docs/architecture/v5-proposal.md:180 keeps execute_script as a direct tool on top of session's exec; if v5 routes it through exec instead, the fix follows that decision.

Acceptance

  • args: ['main'] stays a string on a page with one <main>.
  • Zero $ calls for string arguments.
  • The README execute_script row (README.md:755) and a changelog entry describe the object form.
Lingua principale
TypeScript
Stelle
45
Fork
20
Merge medio
2g 9h
PR unite (30g)
16

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di webdriverio/mcp

Tutte le issue di webdriverio/mcp

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.