-
-
Notifications
You must be signed in to change notification settings - Fork 47
[WIP] Screenshot server #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mrosseel
wants to merge
14
commits into
brickbots:main
Choose a base branch
from
mrosseel:screenshot-server
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
95d13c5
Merged main with the location changes
mrosseel c872394
no ubx yet
mrosseel 51f14f4
Merge branch 'main' of github.com:brickbots/PiFinder
mrosseel 0ec4de8
Revert "no ubx yet"
mrosseel bbcad5c
Merge remote-tracking branch 'origin/main'
mrosseel fd44825
ZMerge branch 'main' of github.com:mrosseel/PiFinder
mrosseel 64f8401
Merge remote-tracking branch 'origin/main'
mrosseel b46636f
Merge remote-tracking branch 'origin/main'
mrosseel 77f79bd
Merge remote-tracking branch 'origin/main'
mrosseel 30fa0dc
Merge branch 'main' of github.com:brickbots/PiFinder
mrosseel 0a71bb5
Merge remote-tracking branch 'upstream'
mrosseel e5c9254
Add screenshot capabilities to the api.
mrosseel 8285a60
Add docs for ui automation API. Should maybe be somewhere else?
mrosseel 6159be9
Merge remote-tracking branch 'upstream/main' into screenshot-server
mrosseel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| # PiFinder UI Automation API | ||
|
|
||
| ## Overview | ||
|
|
||
| The PiFinder web server includes UI automation API endpoints to enable automated testing and iteration workflows. These endpoints allow Claude Code (or any automation tool) to: | ||
|
|
||
| 1. Take screenshots of the current UI state | ||
| 2. Navigate to specific menu locations | ||
| 3. Execute key sequences | ||
| 4. Get the menu structure | ||
|
|
||
| ## API Endpoints | ||
|
|
||
| ### 1. Consolidated Screenshot API | ||
|
|
||
| **Endpoint:** `GET /api/screenshot` or `POST /api/screenshot` | ||
|
|
||
| The single endpoint for all screenshot and navigation needs - always returns a screenshot at native resolution. | ||
|
|
||
| #### GET Request (Simple) | ||
| **Parameters:** | ||
| - `path` (optional): Menu path like "settings/display" | ||
| - `format` (optional): "png" or "jpeg" (default: jpeg) | ||
|
|
||
| **Examples:** | ||
| ```bash | ||
| # Basic screenshot | ||
| curl "http://pifinder.local/api/screenshot" | ||
|
|
||
| # Navigate to menu path then screenshot | ||
| curl "http://pifinder.local/api/screenshot?path=settings/display" | ||
|
|
||
| # PNG format | ||
| curl "http://pifinder.local/api/screenshot?format=png" | ||
| ``` | ||
|
|
||
| #### POST Request (Advanced) | ||
| **Content-Type:** `application/json` | ||
|
|
||
| **Body:** | ||
| ```json | ||
| { | ||
| "path": "settings/display", // optional menu path | ||
| "keys": ["UP", "DOWN", "A"], // optional key sequence | ||
| "format": "jpeg" // optional format | ||
| } | ||
| ``` | ||
|
|
||
| **Available Keys:** | ||
| - Direction: `"UP"`, `"DN"`, `"A"`, `"B"`, `"C"`, `"D"` | ||
| - Special: `"SQUARE"`, `"ALT_PLUS"`, `"ALT_MINUS"`, `"ALT_LEFT"`, etc. | ||
| - Numbers: `0-9` (as integers) | ||
|
|
||
| **Examples:** | ||
| ```bash | ||
| # Navigate to path then execute keys | ||
| curl -X POST "http://pifinder.local/api/screenshot" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"path": "settings", "keys": ["DOWN", "DOWN", "A"]}' | ||
|
|
||
| # Execute key sequence only | ||
| curl -X POST "http://pifinder.local/api/screenshot" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"keys": ["SQUARE", "UP", "A"]}' | ||
| ``` | ||
|
|
||
| ### 2. Menu Structure API | ||
|
|
||
| **Endpoint:** `GET /api/menu-structure` | ||
|
|
||
| Returns the complete menu structure as JSON, including current UI stack state. | ||
|
|
||
| **Example:** | ||
| ```bash | ||
| curl "http://pifinder.local/api/menu-structure" | ||
| ``` | ||
|
|
||
| ## Authentication | ||
|
|
||
| All API endpoints require authentication using the same cookie-based system as the web interface. You'll need to: | ||
|
|
||
| 1. First login at `/login` with the PiFinder password | ||
| 2. Use the session cookie for subsequent API calls | ||
|
|
||
| ## Usage Workflow for Claude Code | ||
|
|
||
| ### Typical Automation Flow: | ||
|
|
||
| 1. **Make code changes** to PiFinder UI components | ||
| 2. **Start the PiFinder app** | ||
| 3. **Take initial screenshot:** | ||
| ```bash | ||
| curl "http://pifinder.local/api/screenshot" > current_ui.jpg | ||
| ``` | ||
| 4. **Navigate to specific screen:** | ||
| ```bash | ||
| curl -X POST "http://pifinder.local/api/screenshot" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"path": "settings/display"}' > settings_screen.jpg | ||
| ``` | ||
| 5. **Test specific interactions:** | ||
| ```bash | ||
| curl -X POST "http://pifinder.local/api/screenshot" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"keys": ["DOWN", "A", "SQUARE"]}' > interaction_result.jpg | ||
| ``` | ||
| 6. **Iterate based on visual feedback** | ||
|
|
||
| ### Advanced Usage: | ||
|
|
||
| **Get menu structure first:** | ||
| ```bash | ||
| curl "http://pifinder.local/api/menu-structure" | jq . | ||
| ``` | ||
|
|
||
| **Complex navigation and testing:** | ||
| ```bash | ||
| curl -X POST "http://pifinder.local/api/screenshot" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"path": "objects", "keys": ["DOWN", "DOWN", "A", "1", "2", "3"]}' > test_result.jpg | ||
| ``` | ||
|
|
||
| ## Key Advantages | ||
|
|
||
| - **Single Endpoint**: One `/api/screenshot` handles all use cases | ||
| - **Always Returns Image**: Every operation ends with visual feedback | ||
| - **Native Resolution**: No scaling - returns actual display resolution | ||
| - **Flexible Navigation**: Supports both path-based and key-sequence navigation | ||
| - **Format Options**: PNG for exact pixels, JPEG for smaller files | ||
|
|
||
| ## Integration with Playwright MCP | ||
|
|
||
| This API works perfectly with Claude Code's Playwright MCP for visual UI testing: | ||
|
|
||
| ```javascript | ||
| // Take screenshot and analyze with Claude Code | ||
| const response = await fetch('http://pifinder.local/api/screenshot', { | ||
| method: 'POST', | ||
| headers: {'Content-Type': 'application/json'}, | ||
| body: JSON.stringify({"path": "radec_entry", "keys": ["SQUARE"]}) | ||
| }); | ||
| const imageBuffer = await response.buffer(); | ||
| // Use mcp__playwright tools to analyze the image | ||
| ``` | ||
|
|
||
| This consolidated approach eliminates API redundancy while providing all the functionality needed for comprehensive UI automation and testing workflows. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested this? Looks like a partial implementation here :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just saw this remark, you are correct, I'll retest to make sure everything works. The text-help kinda depends on this so will do this first