making basic functionality work & add todo list to readme

This commit is contained in:
Michi 2024-11-06 21:42:09 +01:00
parent f32a3b56ce
commit a84d0a512e
5 changed files with 88 additions and 18 deletions

View file

@ -1,21 +1,40 @@
// Background Worker
let steps = [];
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
console.log(message.action);
if (message.action == "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;
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" });
}
sendResponse({ success: true, screenshot: dataUrl });
});
return true;
catch(error){
return sendResponse({ success: false, message: error });
}
case "generateGuide":
return sendResponse({ success: true, guide: steps });;
case "debug":
default:
console.log(message.action);
break;
}
/*chrome.scripting.executeScript({
target: {tabId: tabs[0].id},
files: ['test.js']
});*/
});