Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Remove unwanted (large) keys when sharing feedback (#3766)

sp.wack8392a3fb6b57
diff --git a/frontend/src/components/modals/feedback/FeedbackModal.tsx b/frontend/src/components/modals/feedback/FeedbackModal.tsx
index adec7722aa..4acae073bd 100644
--- a/frontend/src/components/modals/feedback/FeedbackModal.tsx
+++ b/frontend/src/components/modals/feedback/FeedbackModal.tsx
@@ -8,7 +8,7 @@ import { Feedback, sendFeedback } from "#/services/feedbackService";
import toast from "#/utils/toast";
import { getToken } from "#/services/auth";
import Session from "#/services/session";
-import { removeApiKey } from "#/utils/utils";
+import { removeApiKey, removeUnwantedKeys } from "#/utils/utils";
const isEmailValid = (email: string) => {
// Regular expression to validate email format
@@ -95,7 +95,7 @@ function FeedbackModal({
email,
permissions,
token: getToken(),
- trajectory: removeApiKey(Session._history),
+ trajectory: removeApiKey(removeUnwantedKeys(Session._history)),
};
try {
diff --git a/frontend/src/utils/utils.ts b/frontend/src/utils/utils.ts
index 1d4dabd68b..4535ada4a2 100644
--- a/frontend/src/utils/utils.ts
+++ b/frontend/src/utils/utils.ts
@@ -10,9 +10,50 @@ interface EventActionHistory {
LLM_API_KEY?: string;
[key: string]: unknown;
};
+ extras?: {
+ open_page_urls: string[];
+ active_page_index: number;
+ dom_object: Record<string, unknown>;
+ axtree_object: Record<string, unknown>;
+ extra_element_properties: Record<string, unknown>;
+ last_browser_action: string;
+ last_browser_action_error: unknown;
+ focused_element_bid: string;
+ };
[key: string]: unknown;
}
+export const removeUnwantedKeys = (
+ data: EventActionHistory[],
+): EventActionHistory[] => {
+ const UNDESIRED_KEYS = [
+ "open_page_urls",
+ "active_page_index",
+ "dom_object",
+ "axtree_object",
+ "extra_element_properties",
+ "last_browser_action",
+ "last_browser_action_error",
+ "focused_element_bid",
+ ];
+
+ return data.map((item) => {
+ // Create a shallow copy of item
+ const newItem = { ...item };
+
+ // Check if extras exists and delete it from a new extras object
+ if (newItem.extras) {
+ const newExtras = { ...newItem.extras };
+ UNDESIRED_KEYS.forEach((key) => {
+ delete newExtras[key as keyof typeof newExtras];
+ });
+ newItem.extras = newExtras;
+ }
+
+ return newItem;
+ });
+};
+
export const removeApiKey = (
data: EventActionHistory[],
): EventActionHistory[] =>