// Screenshot-flow capture: on each click in the recorded tab, grab a screenshot // plus the click position, building image Steps with pre-placed hotspots. let recording = { active: false, tabId: null, steps: [] }; chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { if (msg.type === "start") { recording = { active: true, tabId: msg.tabId, steps: [] }; chrome.scripting.executeScript({ target: { tabId: msg.tabId }, files: ["content.js"] }); sendResponse({ ok: true }); } else if (msg.type === "click" && recording.active && sender.tab?.id === recording.tabId) { chrome.tabs.captureVisibleTab({ format: "png" }, (dataUrl) => { recording.steps.push({ dataUrl, xPct: msg.xPct, yPct: msg.yPct }); sendResponse({ ok: true }); }); return true; // async } else if (msg.type === "status") { sendResponse({ active: recording.active, count: recording.steps.length }); } else if (msg.type === "stop") { recording.active = false; sendResponse({ steps: recording.steps }); } else if (msg.type === "discard") { recording = { active: false, tabId: null, steps: [] }; sendResponse({ ok: true }); } });