mirror of
https://github.com/michivonah/click-guide.git
synced 2025-12-22 22:16:28 +01:00
40 lines
No EOL
1.4 KiB
JavaScript
40 lines
No EOL
1.4 KiB
JavaScript
// Background Worker
|
|
|
|
let steps = [];
|
|
|
|
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
switch(message.action){
|
|
case "captureScreenshot":
|
|
chrome.tabs.captureVisibleTab(null, { format: "jpeg" }, (dataUrl) => {
|
|
if (chrome.runtime.lastError) {
|
|
console.error("Error capturing screenshot: ", chrome.runtime.lastError);
|
|
sendResponse({ success: false, error: chrome.runtime.lastError });
|
|
return;
|
|
}
|
|
|
|
sendResponse({ success: true, screenshot: dataUrl });
|
|
});
|
|
return true;
|
|
case "saveStep":
|
|
try{
|
|
const step = {
|
|
"label":message.stepLabel,
|
|
"description":"Short description of the step",
|
|
"action":message.triggerName,
|
|
"element":message.stepElement,
|
|
"image":message.image
|
|
}
|
|
steps.push(step);
|
|
return sendResponse({ success: true, message: "Step successfully added to guide" });
|
|
}
|
|
catch(error){
|
|
return sendResponse({ success: false, message: error });
|
|
}
|
|
case "generateGuide":
|
|
return sendResponse({ success: true, guide: steps });;
|
|
case "debug":
|
|
default:
|
|
console.log(message.action);
|
|
break;
|
|
}
|
|
}); |