From 7ba06dedfbe841746f0ad6c8858362f699733739 Mon Sep 17 00:00:00 2001 From: Mengdi Chen Date: Tue, 18 Jun 2024 18:35:02 -0700 Subject: [PATCH] feat: expose debug mode for main world via content script (#190) --- src/common/TaskUI.tsx | 40 +++++++++++++-------- src/pages/content/index.ts | 2 -- utils/plugins/inline-vite-preload-script.ts | 31 ++++++++++++++++ vite.config.ts | 6 ++-- 4 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 utils/plugins/inline-vite-preload-script.ts diff --git a/src/common/TaskUI.tsx b/src/common/TaskUI.tsx index 652bdd7..35f8aee 100644 --- a/src/common/TaskUI.tsx +++ b/src/common/TaskUI.tsx @@ -1,10 +1,9 @@ -import React, { useCallback, useState } from "react"; +import React, { useCallback } from "react"; import { Button, Box, HStack, Spacer, - Textarea, useToast, Alert, AlertIcon, @@ -19,6 +18,19 @@ import TaskStatus from "./TaskStatus"; import RecommendedTasks from "./RecommendedTasks"; import AutosizeTextarea from "./AutosizeTextarea"; +const injectContentScript = async () => { + const [tab] = await chrome.tabs.query({ currentWindow: true, active: true }); + if (!tab || !tab.id) { + return; + } + + await chrome.scripting.executeScript({ + target: { tabId: tab.id }, + files: ["src/pages/contentInjected/index.js"], + world: "MAIN", + }); +}; + function ActionExecutor() { const state = useAppState((state) => ({ attachDebugger: state.currentTask.actions.attachDebugger, @@ -27,28 +39,26 @@ function ActionExecutor() { prepareLabels: state.currentTask.actions.prepareLabels, showImagePrompt: state.currentTask.actions.showImagePrompt, })); - const [action, setAction] = useState(`{ - "thought": "try searching", - "action": "click('search')" -} -`); return ( -