From f5a82809e028e27fabd2bd47805c0acf8577f752 Mon Sep 17 00:00:00 2001 From: milldr Date: Fri, 22 May 2026 15:08:57 -0400 Subject: [PATCH] fix(quick-add): improve meal category selector and retry logic --- src/kernel/food-dialog.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/kernel/food-dialog.ts b/src/kernel/food-dialog.ts index cd4d023..97bff57 100644 --- a/src/kernel/food-dialog.ts +++ b/src/kernel/food-dialog.ts @@ -61,19 +61,25 @@ export function buildFoodDialogCode(options: FoodDialogOptions = {}): string { return false; } - // Right-click meal category with retry (GWT context menus can be flaky) + // Right-click meal category with retry (GWT context menus can be flaky + // and meal labels may not render immediately) let menuVisible = false; for (let attempt = 0; attempt < 3 && !menuVisible; attempt++) { if (attempt > 0) { await page.keyboard.press('Escape'); await page.mouse.click(1, 1); - await page.waitForTimeout(1000); + await page.waitForTimeout(2000); } const clicked = await rightClickFirst([ + 'td:text("' + ${mealLabelVar} + '")', + 'div:text("' + ${mealLabelVar} + '")', 'text="' + ${mealLabelVar} + '"', - ':has-text("' + ${mealLabelVar} + '")', ], 'meal category'); if (!clicked) { + if (attempt < 2) { + await page.waitForTimeout(2000); + continue; + } return { success: false, error: '${mealCategoryError}' + ${mealLabelVar} + '" in diary' }; } menuVisible = await page.waitForSelector('text="Add Food..."', { timeout: 3000 })