jackwener/OpenCLI · error · CommandExecutionError
Gmail ${operation} could not find the search input
Error message
Gmail ${operation} could not find the search input What it means
submitSearch throws this CommandExecutionError when the in-page evaluate focused/selecting input[name="q"] returns false — i.e. the search input that ensureGmailReady saw earlier has disappeared by the time the search runs. The library aborts rather than typing into a nonexistent field.
Source
Thrown at clis/gmail/utils.js:461
const parsedDate = row.dateText ? new Date(row.dateText) : null;
return {
...row,
threadId: cleanString(target).replace(/^#/, ''),
date: parsedDate && !Number.isNaN(parsedDate.getTime()) ? parsedDate.toISOString() : null,
body: cleanString(row.body).slice(0, MAX_BODY_CHARS) || null,
};
}).map(({ dateText: _dateText, ...row }) => row);
}
async function submitSearch(page, query, operation) {
const prepared = unwrapBrowserResult(await page.evaluate(`() => {
const field = document.querySelector('input[name="q"]');
if (!field) return false;
field.focus();
field.select();
return true;
}`), `${operation} search preparation`);
if (prepared !== true) throw new CommandExecutionError(`Gmail ${operation} could not find the search input`);
if (typeof page.nativeType !== 'function') {
throw new CommandExecutionError(`Gmail ${operation} requires native browser input`);
}
await page.nativeType(query);
const actual = unwrapBrowserResult(await page.evaluate(`() => document.querySelector('input[name="q"]')?.value || ''`), `${operation} search input verification`);
if (actual !== query) throw new CommandExecutionError(`Gmail ${operation} could not set the search query exactly`);
if (typeof page.cdp === 'function') {
const key = { key: 'Enter', code: 'Enter', windowsVirtualKeyCode: 13, nativeVirtualKeyCode: 13 };
await page.cdp('Input.dispatchKeyEvent', { type: 'rawKeyDown', ...key });
await page.cdp('Input.dispatchKeyEvent', { type: 'keyUp', ...key });
} else if (typeof page.nativeKeyPress === 'function') {
await page.nativeKeyPress('Enter');
} else {
throw new CommandExecutionError(`Gmail ${operation} requires native browser keyboard input`);
}
}
export async function queryThreads(page, query, { account = 0, limit = DEFAULT_LIMIT } = {}) {View on GitHub (pinned to 49907e53dc)
Solutions
- Retry the command; the race usually resolves on a second attempt after Gmail settles
- Reload Gmail and wait for full load before running the operation
- Avoid running concurrent Gmail operations on the same page
- Serialize operations with a small delay after page load so Gmail finishes initial rendering
Example fix
// before: fire immediately after readiness
await queryThreads(page, 'in:unread');
// after: settle, then retry-once on failure
await page.sleep(2);
try {
await queryThreads(page, 'in:unread');
} catch (e) {
await page.reload(); await page.sleep(3);
await queryThreads(page, 'in:unread');
} Defensive patterns
Strategy: retry
Validate before calling
const present = await page.evaluate('() => !!document.querySelector("input[name=q]")');
if (!present) throw new Error('Gmail search box missing; reload and let the UI settle before searching'); Try / catch
try {
await queryThreads(page, 'is:starred');
} catch (e) {
if (/could not find the search input/.test(e.message)) {
await page.reload(); await page.sleep(3); // let Gmail finish rendering
return queryThreads(page, 'is:starred');
}
throw e;
} Prevention
- Wait for full Gmail render before operations; avoid races right after load
- Never run concurrent Gmail operations on the same page
- Dismiss dialogs/interstitials that displace the search box
- Retry once on this race — it usually clears after the UI settles
When it happens
Trigger: queryThreads or listLabels calls submitSearch after readiness, but Gmail re-rendered the DOM (view switch, navigation, load race) removing the search box between the readiness probe and the type step.
Common situations: Gmail auto-navigated or showed a dialog/interstitial right after load; slow render where the probe saw an early DOM then it was replaced; running multiple operations concurrently on the same page causing navigation races.
Related errors
- Failed to extract Booking.com cards: ${err?.message || err}
- coupang add-to-cart evaluation failed: ${error?.message || e
- coupang search
- coupang search extraction failed: ${error?.message || error}
- Ctrip cruise port page did not render (state=${String(portWa
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/2f62596a87f5e76f.
Report an issue: GitHub.