jackwener/OpenCLI · error

Search input not found

Error message

Search input not found

What it means

The search command opens Discord's search bar (Meta+F / Ctrl+F) and injects a script that queries '[aria-label*="Search"], [class*="searchBar" input, [placeholder*="Search"]'. If no element matches, the injected script throws Error('Search input not found'), which surfaces as this error. It means Discord's search box was not present in the DOM when the script ran.

Source

Thrown at clis/discord-app/search.js:23

    name: 'search',
    access: 'read',
    description: 'Search messages in the current Discord server/channel (Cmd+F)',
    domain: 'localhost',
    strategy: Strategy.UI,
    browser: true,
    args: [{ name: 'query', required: true, positional: true, help: 'Search query' }],
    columns: ['Index', 'Author', 'Message'],
    func: async (page, kwargs) => {
        const query = kwargs.query;
        // Open search with Cmd+F
        const isMac = process.platform === 'darwin';
        await page.pressKey(isMac ? 'Meta+F' : 'Control+F');
        await page.wait(0.5);
        // Type query into search box
        await page.evaluate(`
      (function(q) {
        const input = document.querySelector('[aria-label*="Search"], [class*="searchBar"] input, [placeholder*="Search"]');
        if (!input) throw new Error('Search input not found');
        input.focus();
        const setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
        setter.call(input, q);
        input.dispatchEvent(new Event('input', { bubbles: true }));
      })(${JSON.stringify(query)})
    `);
        await page.pressKey('Enter');
        await page.wait(2);
        // Scrape search results
        const searchState = await page.evaluate(`
      (function() {
        const items = [];
        const resultNodes = document.querySelectorAll('[class*="searchResult_"], [id*="search-result"]');
        
        resultNodes.forEach((node, i) => {
          const author = node.querySelector('[class*="username"]')?.textContent?.trim() || '—';
          const content = node.querySelector('[id^="message-content-"], [class*="messageContent"]')?.textContent?.trim() || node.textContent?.trim();
          items.push({

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Navigate into a server channel before running search (search requires a guild/channel context).
  2. Increase the wait after pressing Ctrl+F (e.g. page.wait(1.0)) so the input exists, then retry.
  3. Click into the Discord window to ensure the shortcut reaches the app.
  4. Update the selector list to match current Discord search-input attributes if the DOM changed.

Example fix

// before
await page.pressKey('Control+F');
await page.wait(0.5);
// after
await page.pressKey('Control+F');
await page.waitForSelector('[aria-label*="Search"]');
await page.wait(0.5);
Defensive patterns

Strategy: retry

Validate before calling

const input = await page.evaluate(`Boolean(document.querySelector('[aria-label*="Search"], [class*="searchBar"] input, [placeholder*="Search"]'))`);
if (!input) { await page.pressKey('Control+F'); await page.wait(1); }

Type guard

function searchInputVisible(state) { return state === true; }

Try / catch

try {
  await run('discord-app search --query=...');
} catch (e) {
  if (/Search input not found/.test(e.message)) {
    await navigateIntoChannel();
    await page.wait(1);
    await run('discord-app search --query=...'); // retry once
  }
}

Prevention

When it happens

Trigger: Running 'discord-app search' while not inside a server/channel view (search bar unavailable on home screen), the Ctrl+F focus animation hasn't completed when the selector runs, the search input is inside a modal that hasn't rendered, or Discord changed its search input markup/classes.

Common situations: Bot profile sitting on the friends/DMs home page; slow machine where 0.5s wait isn't enough; Discord web app update renaming classes/aria-labels; keyboard shortcut intercepted by OS or another focused element.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/023379d93805fc1f. Report an issue: GitHub.