{"record":{"id":"023379d93805fc1f","repo":"jackwener/OpenCLI","slug":"search-input-not-found","errorCode":null,"errorMessage":"Search input not found","messagePattern":"Search input not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/discord-app/search.js","lineNumber":23,"sourceCode":"    name: 'search',\n    access: 'read',\n    description: 'Search messages in the current Discord server/channel (Cmd+F)',\n    domain: 'localhost',\n    strategy: Strategy.UI,\n    browser: true,\n    args: [{ name: 'query', required: true, positional: true, help: 'Search query' }],\n    columns: ['Index', 'Author', 'Message'],\n    func: async (page, kwargs) => {\n        const query = kwargs.query;\n        // Open search with Cmd+F\n        const isMac = process.platform === 'darwin';\n        await page.pressKey(isMac ? 'Meta+F' : 'Control+F');\n        await page.wait(0.5);\n        // Type query into search box\n        await page.evaluate(`\n      (function(q) {\n        const input = document.querySelector('[aria-label*=\"Search\"], [class*=\"searchBar\"] input, [placeholder*=\"Search\"]');\n        if (!input) throw new Error('Search input not found');\n        input.focus();\n        const setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;\n        setter.call(input, q);\n        input.dispatchEvent(new Event('input', { bubbles: true }));\n      })(${JSON.stringify(query)})\n    `);\n        await page.pressKey('Enter');\n        await page.wait(2);\n        // Scrape search results\n        const searchState = await page.evaluate(`\n      (function() {\n        const items = [];\n        const resultNodes = document.querySelectorAll('[class*=\"searchResult_\"], [id*=\"search-result\"]');\n        \n        resultNodes.forEach((node, i) => {\n          const author = node.querySelector('[class*=\"username\"]')?.textContent?.trim() || '—';\n          const content = node.querySelector('[id^=\"message-content-\"], [class*=\"messageContent\"]')?.textContent?.trim() || node.textContent?.trim();\n          items.push({","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/discord-app/search.js#L5-L41","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Navigate into a server channel before running search (search requires a guild/channel context).","Increase the wait after pressing Ctrl+F (e.g. page.wait(1.0)) so the input exists, then retry.","Click into the Discord window to ensure the shortcut reaches the app.","Update the selector list to match current Discord search-input attributes if the DOM changed."],"exampleFix":"// before\nawait page.pressKey('Control+F');\nawait page.wait(0.5);\n// after\nawait page.pressKey('Control+F');\nawait page.waitForSelector('[aria-label*=\"Search\"]');\nawait page.wait(0.5);","handlingStrategy":"retry","validationCode":"const input = await page.evaluate(`Boolean(document.querySelector('[aria-label*=\"Search\"], [class*=\"searchBar\"] input, [placeholder*=\"Search\"]'))`);\nif (!input) { await page.pressKey('Control+F'); await page.wait(1); }","typeGuard":"function searchInputVisible(state) { return state === true; }","tryCatchPattern":"try {\n  await run('discord-app search --query=...');\n} catch (e) {\n  if (/Search input not found/.test(e.message)) {\n    await navigateIntoChannel();\n    await page.wait(1);\n    await run('discord-app search --query=...'); // retry once\n  }\n}","preventionTips":["Navigate into a server channel before searching.","Wait after pressing Ctrl+F so the input mounts.","Focus the Discord window so keyboard shortcuts land in the app.","Re-check selectors after Discord web app updates."],"tags":["discord","dom-selector","search","browser-automation"],"backgroundTag":"element-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}