From 46ad15be6cf882eaff4c2fd571c875b4552bf54e Mon Sep 17 00:00:00 2001 From: Lingjie Feng Date: Sun, 19 May 2024 23:36:24 -0400 Subject: [PATCH] feat: send error message --- benchmark.py | 6 +++++- process_log.py | 2 +- src/pages/background/index.ts | 8 ++------ src/pages/content/injected.ts | 4 +++- tasks_test.jsonl | 7 +++++++ 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/benchmark.py b/benchmark.py index 756ea2f..db7becc 100644 --- a/benchmark.py +++ b/benchmark.py @@ -35,7 +35,7 @@ def setup_driver(): chrome_options = Options() # Load the unpacked webwand chrome extension chrome_options.add_argument("--load-extension=./dist") - chrome_options.add_argument("--window-size=1600,900") + chrome_options.add_argument("--window-size=1600,1000") service = Service(ChromeDriverManager().install()) driver = webdriver.Chrome(service=service, options=chrome_options) # Set script timeout to 120 seconds @@ -60,10 +60,13 @@ def add_task_listener(driver, task_id, max_retries=3): script = f""" var callback = arguments[0]; var eventListener = function (e) {{ + console.log("received evnet"); + console.log(e); if (e.detail.type == 'history') {{ if (e.detail.status === 'success' || e.detail.status === 'error') {{ callback({{status: e.detail.status, type: 'history', data: e.detail.data, errorMessage: e.detail.errorMessage}}); document.removeEventListener('TaskUpdate', eventListener); // Optional: remove if you need continuous listening + console.log("listener removed after history"); }} // Does not do anything when the status is 'running' or 'idle'. // The status 'interrupted' will never be triggered automatically. @@ -75,6 +78,7 @@ def add_task_listener(driver, task_id, max_retries=3): }}; document.addEventListener('TaskUpdate', eventListener); + console.log("added event listener"); """ attempts = 0 diff --git a/process_log.py b/process_log.py index 6a2e065..bc052d0 100644 --- a/process_log.py +++ b/process_log.py @@ -4,7 +4,7 @@ def process_log_file(log_file_path): with open(log_file_path, 'r') as file: log_data = file.readlines() - task_status_pattern = re.compile(r"Task ([\w\s-]+--\d+) status: (script-error|success|fail|doc-unload-max-retry|js-script-timeout|webdriver-error|python-script-error)") + task_status_pattern = re.compile(r"Task ([\w\s-]+--\d+) status: (script-error|success|error|fail|doc-unload-max-retry|js-script-timeout|webdriver-error|python-script-error)") tasks = [] for line in log_data: diff --git a/src/pages/background/index.ts b/src/pages/background/index.ts index 5a47815..4b92c1e 100644 --- a/src/pages/background/index.ts +++ b/src/pages/background/index.ts @@ -32,11 +32,7 @@ chrome.runtime.onMessage.addListener(async (message) => { const tab = await findActiveTab(); if (tab?.id !== undefined) { console.log("sending updateHistory message to content script"); - chrome.tabs.sendMessage(tab.id, { - type: "updateHistory", - status: message.status, - history: message.history, - }); + chrome.tabs.sendMessage(tab.id, message); } } else if (message.action === "sendScreenshot") { const imageDataBase64 = message.imgData.split(",")[1] || message.imgData; @@ -44,7 +40,7 @@ chrome.runtime.onMessage.addListener(async (message) => { if (tab?.id !== undefined) { console.log("sending sendScreenshot message to content script"); chrome.tabs.sendMessage(tab.id, { - type: "sendScreenshot", + action: message.action, status: message.status, imgData: imageDataBase64, }); diff --git a/src/pages/content/injected.ts b/src/pages/content/injected.ts index a06ca14..4b09ec3 100644 --- a/src/pages/content/injected.ts +++ b/src/pages/content/injected.ts @@ -31,13 +31,14 @@ document.addEventListener(RunTask, function () { // Listen for messages from the background script chrome.runtime.onMessage.addListener(function (message) { - switch (message.type) { + switch (message.action) { case "updateHistory": console.log("sending status and history event"); dispatchCustomEvent("TaskUpdate", { type: "history", status: message.status, data: message.history, + errorMessage: message.error, }); break; case "sendScreenshot": @@ -56,6 +57,7 @@ type CustomEventDetail = { status: string; // eslint-disable-next-line @typescript-eslint/no-explicit-any data: any; + errorMessage?: string; }; function dispatchCustomEvent(eventType: string, detail: CustomEventDetail) { diff --git a/tasks_test.jsonl b/tasks_test.jsonl index e69de29..33b0653 100644 --- a/tasks_test.jsonl +++ b/tasks_test.jsonl @@ -0,0 +1,7 @@ +{"web_name": "Coursera", "id": "Coursera--31", "ques": "Search for the course 'Exploring Quantum Physics' on Coursera, offered by the University of Maryland, College Park. Identify the percentage (rounded) of 5-star ratings in the reviews.", "web": "https://www.coursera.org/"} +{"web_name": "Coursera", "id": "Coursera--32", "ques": "Search for 'Data Analysis' courses on Coursera. Apply filters to find courses that are 'Beginner Level' and have a duration ranging from 1 to 3 months. Determine the total count of courses that match these specifications.", "web": "https://www.coursera.org/"} +{"web_name": "Coursera", "id": "Coursera--33", "ques": "Find a beginner level Coursera course related to \"Internet of Things (IoT)\" with a high rating. Provide the course name, instructor's name, and a brief summary of the skills that will be taught.", "web": "https://www.coursera.org/"} +{"web_name": "Coursera", "id": "Coursera--34", "ques": "Find the course on Coursera named 'Essentials of Global Health'. Determine the instructor of this course and summarize his bio, note if there are any additional courses he offers on Coursera.", "web": "https://www.coursera.org/"} +{"web_name": "Coursera", "id": "Coursera--35", "ques": "Find a Coursera course on Sustainable Agriculture practices, and detail the course's objectives and the background of the lead instructor.", "web": "https://www.coursera.org/"} +{"web_name": "Coursera", "id": "Coursera--36", "ques": "Browse Coursera, which universities offer Master of Advanced Study in Engineering degrees? Tell me what is the latest application deadline for this degree?", "web": "https://www.coursera.org/"} +{"web_name": "Coursera", "id": "Coursera--39", "ques": "Find the Space Safety course offered by TUM on Coursera. How many videos are there in module 2? What is the name of each video?", "web": "https://www.coursera.org/"} \ No newline at end of file