{"record":{"id":"f96959659b073940","repo":"jackwener/OpenCLI","slug":"instagram-fallback-file-injection-failed","errorCode":null,"errorMessage":"Instagram fallback file injection failed","messagePattern":"Instagram fallback file injection failed","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/instagram/post.js","lineNumber":549,"sourceCode":"          const bytes = new Uint8Array(binary.length);\n          for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);\n          const blob = new Blob([bytes], { type: img.type });\n          const file = new File([blob], img.name, { type: img.type });\n          dt.items.add(file);\n        }\n        Object.defineProperty(input, 'files', { value: dt.files, configurable: true });\n        input.dispatchEvent(new Event('change', { bubbles: true }));\n        input.dispatchEvent(new Event('input', { bubbles: true }));\n        cleanup();\n        return { ok: true, count: dt.files.length };\n      } catch (error) {\n        cleanup();\n        return { ok: false, error: String(error) };\n      }\n    })()\n  `);\n    if (!result?.ok) {\n        throw new CommandExecutionError(result?.error || 'Instagram fallback file injection failed');\n    }\n}\nasync function dispatchUploadEvents(page, selector) {\n    await page.evaluate(`\n    (() => {\n      const input = document.querySelector(${JSON.stringify(selector)});\n      if (!(input instanceof HTMLInputElement)) return { ok: false };\n      input.dispatchEvent(new Event('input', { bubbles: true }));\n      input.dispatchEvent(new Event('change', { bubbles: true }));\n      return { ok: true };\n    })()\n  `);\n}\nexport function buildInspectUploadStageJs() {\n    return `\n    (() => {\n      const isVisible = (el) => {\n        if (!(el instanceof HTMLElement)) return false;","sourceCodeStart":531,"sourceCodeEnd":567,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/post.js#L531-L567","documentation":"injectImageViaBrowser is the fallback path that injects files into the composer's file input via in-page JS when page.setFileInput is unavailable. If the injected script returns ok:false (or returns nothing at all), the library surfaces the script's error string, defaulting to this message. It indicates the browser-side DOM injection could not complete.","triggerScenarios":"uploadMedia falls back to injectImageViaBrowser after a setFileInput failure, and the in-page script hits an exception or fails to set input.files, returning { ok:false, error } — the thrown message is result.error or the default fallback string.","commonSituations":"Browser mode without setFileInput support (non-Browser-Bridge driver), page navigated away mid-upload, DOMPurify/React intercepting synthetic file assignment, or selector stale after composer re-render.","solutions":["Re-run with Browser Bridge mode so page.setFileInput is available and the fallback is never needed","Re-resolve the upload selector (resolveUploadSelectors) before retrying, the old one may be stale","Screenshot the page to check whether the composer is still open and the input still exists","Retry the post; transient SPA re-renders often break one injection attempt but not the next"],"exampleFix":"// before\nawait uploadMedia(page, mediaItems, selector);\n// after\ntry {\n  await uploadMedia(page, mediaItems, selector);\n} catch (e) {\n  if (String(e.message).includes('fallback file injection')) {\n    const fresh = await resolveUploadSelectors(page, mediaItems);\n    await uploadMedia(page, mediaItems, fresh[0]);\n  } else throw e;\n}","handlingStrategy":"fallback","validationCode":"if (typeof page.setFileInput !== 'function') {\n  console.warn('setFileInput unavailable; browser-injection fallback will be used');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await uploadMedia(page, mediaItems, selector);\n} catch (e) {\n  if (String(e.message).includes('fallback file injection failed')) {\n    const selectors = await resolveUploadSelectors(page, mediaItems);\n    await uploadMedia(page, mediaItems, selectors[0]);\n  } else throw e;\n}","preventionTips":["Prefer Browser Bridge mode so the injection fallback is rarely exercised","Re-resolve selectors before each upload attempt to avoid stale references","Keep the composer as the active tab; navigation mid-upload breaks injection"],"tags":["instagram","file-upload","browser-automation"],"backgroundTag":"file-injection-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}