Skip to content

Commit

Permalink
feat: send error message
Browse files Browse the repository at this point in the history
  • Loading branch information
lynchee-owo committed May 20, 2024
1 parent cc36e31 commit 46ad15b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
6 changes: 5 additions & 1 deletion benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion process_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 2 additions & 6 deletions src/pages/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,15 @@ 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;
const tab = await findActiveTab();
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,
});
Expand Down
4 changes: 3 additions & 1 deletion src/pages/content/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions tasks_test.jsonl
Original file line number Diff line number Diff line change
@@ -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/"}

0 comments on commit 46ad15b

Please sign in to comment.