{"record":{"id":"78bc9671a35469a1","repo":"garrytan/gstack","slug":"no-modification-at-index-idx-history-has-mod","errorCode":null,"errorMessage":"No modification at index ${idx}. History has ${modificationHistory.length} entries${evictedNote}.","messagePattern":"No modification at index (.+?)\\. History has (.+?) entries(.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"browse/src/cdp-inspector.ts","lineNumber":618,"sourceCode":"    sourceLine,\n    timestamp: Date.now(),\n    method,\n  };\n\n  pushModification(modification);\n  return modification;\n}\n\n/**\n * Undo a modification by index (or last if no index given).\n */\nexport async function undoModification(page: Page, index?: number): Promise<void> {\n  const idx = index ?? modificationHistory.length - 1;\n  if (idx < 0 || idx >= modificationHistory.length) {\n    const evictedNote = modHistoryTotalPushed > MOD_HISTORY_CAP\n      ? ` (most recent ${MOD_HISTORY_CAP} only — ${modHistoryTotalPushed - MOD_HISTORY_CAP} earlier entries evicted at the cap)`\n      : '';\n    throw new Error(\n      `No modification at index ${idx}. History has ${modificationHistory.length} entries${evictedNote}.`,\n    );\n  }\n\n  const mod = modificationHistory[idx];\n\n  if (mod.method === 'setStyleTexts') {\n    // Try to restore via CDP\n    try {\n      await modifyStyle(page, mod.selector, mod.property, mod.oldValue);\n      // Remove the undo modification from history (it's a restore, not a new mod)\n      modificationHistory.pop();\n    } catch (err: any) {\n      // Fall back to inline restore — CDP may have disconnected or stylesheet changed\n      if (!err?.message?.includes('closed') && !err?.message?.includes('Target') && !err?.message?.includes('style') && !err?.message?.includes('not found') && !err?.message?.includes('Element')) throw err;\n      await page.evaluate(\n        ([sel, prop, val]) => {\n          const el = document.querySelector(sel);","sourceCodeStart":600,"sourceCodeEnd":636,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/cdp-inspector.ts#L600-L636","documentation":"Error \"No modification at index ${idx}. History has ${modificationHistory.length} entries${evictedNote}.\" thrown in garrytan/gstack.","triggerScenarios":"Thrown at browse/src/cdp-inspector.ts:618 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}