From 465ef415a3048e4cdaeab1193f8f1b6603178f96 Mon Sep 17 00:00:00 2001 From: Snider Date: Fri, 13 Mar 2026 16:01:03 +0000 Subject: [PATCH] feat(webview): add IPC message types and own types Co-Authored-By: Claude Opus 4.6 --- pkg/webview/messages.go | 171 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 pkg/webview/messages.go diff --git a/pkg/webview/messages.go b/pkg/webview/messages.go new file mode 100644 index 0000000..4681e28 --- /dev/null +++ b/pkg/webview/messages.go @@ -0,0 +1,171 @@ +// pkg/webview/messages.go +package webview + +import "time" + +// --- Queries (read-only) --- + +// QueryURL gets the current page URL. Result: string +type QueryURL struct{ Window string `json:"window"` } + +// QueryTitle gets the current page title. Result: string +type QueryTitle struct{ Window string `json:"window"` } + +// QueryConsole gets captured console messages. Result: []ConsoleMessage +type QueryConsole struct { + Window string `json:"window"` + Level string `json:"level,omitempty"` // filter by type: "log", "warn", "error", "info", "debug" + Limit int `json:"limit,omitempty"` // max messages (0 = all) +} + +// QuerySelector finds a single element. Result: *ElementInfo (nil if not found) +type QuerySelector struct { + Window string `json:"window"` + Selector string `json:"selector"` +} + +// QuerySelectorAll finds all matching elements. Result: []*ElementInfo +type QuerySelectorAll struct { + Window string `json:"window"` + Selector string `json:"selector"` +} + +// QueryDOMTree gets HTML content. Result: string (outerHTML) +type QueryDOMTree struct { + Window string `json:"window"` + Selector string `json:"selector,omitempty"` // empty = full document +} + +// --- Tasks (side-effects) --- + +// TaskEvaluate executes JavaScript. Result: any (JS return value) +type TaskEvaluate struct { + Window string `json:"window"` + Script string `json:"script"` +} + +// TaskClick clicks an element. Result: nil +type TaskClick struct { + Window string `json:"window"` + Selector string `json:"selector"` +} + +// TaskType types text into an element. Result: nil +type TaskType struct { + Window string `json:"window"` + Selector string `json:"selector"` + Text string `json:"text"` +} + +// TaskNavigate navigates to a URL. Result: nil +type TaskNavigate struct { + Window string `json:"window"` + URL string `json:"url"` +} + +// TaskScreenshot captures the page as PNG. Result: ScreenshotResult +type TaskScreenshot struct{ Window string `json:"window"` } + +// TaskScroll scrolls to an absolute position (window.scrollTo). Result: nil +type TaskScroll struct { + Window string `json:"window"` + X int `json:"x"` + Y int `json:"y"` +} + +// TaskHover hovers over an element. Result: nil +type TaskHover struct { + Window string `json:"window"` + Selector string `json:"selector"` +} + +// TaskSelect selects an option in a