From a246d302c26e549919a8e648323552564bc1be63 Mon Sep 17 00:00:00 2001 From: Sayan Samanta Date: Tue, 8 Jul 2025 11:38:37 -0700 Subject: [PATCH 1/5] try to autodetect display to record --- server/Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/Makefile b/server/Makefile index 606ab870..f4fc5d8f 100644 --- a/server/Makefile +++ b/server/Makefile @@ -28,7 +28,7 @@ build: | $(BIN_DIR) go build -o $(BIN_DIR)/api ./cmd/api dev: build $(RECORDING_DIR) - OUTPUT_DIR=$(RECORDING_DIR) ./bin/api + OUTPUT_DIR=$(RECORDING_DIR) DISPLAY_NUM=$(DISPLAY_NUM) ./bin/api test: go vet ./... @@ -38,3 +38,12 @@ clean: @rm -rf $(BIN_DIR) @rm -f openapi-3.0.yaml @echo "Clean complete" + +DISPLAY_NUM := $(shell \ + if [ "$$(uname)" = "Linux" ]; then \ + echo "1"; \ + elif [ "$$(uname)" = "Darwin" ]; then \ + ffmpeg -f avfoundation -list_devices true -i "" 2>&1 | grep "Capture screen" | head -1 | sed 's/.*\[\([0-9]*\)\].*/\1/' 2>/dev/null || echo "2"; \ + else \ + echo "0"; \ + fi) From 0d6aacd2c310b0bb06877bdb8e6cb533c6b63dbd Mon Sep 17 00:00:00 2001 From: Sayan Samanta Date: Tue, 8 Jul 2025 11:38:43 -0700 Subject: [PATCH 2/5] update copy --- README.md | 23 +++++++++++++++++++++++ server/README.md | 27 ++++++++++++++------------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 9230297f..c89cf167 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,29 @@ You can use the embedded live view to monitor and control the browser. The live - The live view is read/write by default. You can set it to read-only by adding `-e ENABLE_READONLY_VIEW=true \` in `docker run`. - Replays are currently a work in progress. There is some source code for it throughout the repo. +## Replay Capture + +You can use the embedded recording server to capture recordings of the entire screen in our headful images. It allows for one recording at a time and can be enabled with `WITH_KERNEL_IMAGES_API=true` + +For example: + +```bash +cd /images/chromium-headful +IMAGE=kernel-docker ENABLE_WEBRTC=true ./run-docker.sh + + +# 1. Start a new recording +curl http://localhost:10001/recording/start -d {} + +# recording in progress - run your agent + +# 2. Stop recording +curl http://localhost:10001/recording/stop -d {} + +# 3. Download the recorded file +curl http://localhost:10001/recording/download --output recording.mp4 +``` + ## Documentation This repo powers our managed [browser infrastructure](https://docs.onkernel.com). diff --git a/server/README.md b/server/README.md index 6da30768..9eef65d7 100644 --- a/server/README.md +++ b/server/README.md @@ -7,10 +7,10 @@ A REST API server to start, stop, and download screen recordings. ### Required Software - **Go 1.24.3+** - Programming language runtime -- **FFmpeg** - Video recording engine +- **ffmpeg** - Video recording engine - macOS: `brew install ffmpeg` - Linux: `sudo apt install ffmpeg` or `sudo yum install ffmpeg` -- **Node.js/pnpm** - For OpenAPI code generation +- **pnpm** - For OpenAPI code generation - `npm install -g pnpm` ### System Requirements @@ -33,28 +33,29 @@ The server will start on port 10001 by default and log its configuration. ```bash # 1. Start a new recording -curl http://localhost:10001/recording/start +curl http://localhost:10001/recording/start -d {} # (recording in progress) -# 2. Stop recording and clean up resources -curl http://localhost:10001/recording/stop +# 2. Stop recording +curl http://localhost:10001/recording/stop -d {} # 3. Download the recorded file -curl http://localhost:10001/recording/download --output foo.mp4 +curl http://localhost:10001/recording/download --output recording.mp4 ``` ### ⚙️ Configuration Configure the server using environment variables: -| Variable | Default | Description | -| ------------- | ------- | --------------------------------- | -| `PORT` | `10001` | HTTP server port | -| `FRAME_RATE` | `10` | Default recording framerate (fps) | -| `DISPLAY_NUM` | `1` | Display/screen number to capture | -| `MAX_SIZE_MB` | `500` | Default maximum file size (MB) | -| `OUTPUT_DIR` | `.` | Directory to save recordings | +| Variable | Default | Description | +| -------------- | --------- | ------------------------------------------- | +| `PORT` | `10001` | HTTP server port | +| `FRAME_RATE` | `10` | Default recording framerate (fps) | +| `DISPLAY_NUM` | `1` | Display/screen number to capture | +| `MAX_SIZE_MB` | `500` | Default maximum file size (MB) | +| `OUTPUT_DIR` | `.` | Directory to save recordings | +| `FFMPEG_PATH` | `ffmpeg` | Path to the ffmpeg binary | #### Example Configuration From 1fb8525ed9f2d1d416666203df2f0ee14e2f1b36 Mon Sep 17 00:00:00 2001 From: Sayan Samanta Date: Thu, 10 Jul 2025 17:32:53 -0700 Subject: [PATCH 3/5] fix port --- images/chromium-headful/run-docker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/chromium-headful/run-docker.sh b/images/chromium-headful/run-docker.sh index 1d713f3d..b9962299 100755 --- a/images/chromium-headful/run-docker.sh +++ b/images/chromium-headful/run-docker.sh @@ -27,7 +27,7 @@ RUN_ARGS=( ) if [[ "${WITH_KERNEL_IMAGES_API:-}" == "true" ]]; then - RUN_ARGS+=( -p 444:10001 ) + RUN_ARGS+=( -p 10001:10001 ) RUN_ARGS+=( -e WITH_KERNEL_IMAGES_API=true ) fi From 8395faec4df69183f1abe79477e314afd1dd251e Mon Sep 17 00:00:00 2001 From: Sayan Samanta Date: Thu, 10 Jul 2025 17:49:48 -0700 Subject: [PATCH 4/5] note about quicktime --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c89cf167..9a488609 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,6 @@ For example: cd /images/chromium-headful IMAGE=kernel-docker ENABLE_WEBRTC=true ./run-docker.sh - # 1. Start a new recording curl http://localhost:10001/recording/start -d {} @@ -163,6 +162,8 @@ curl http://localhost:10001/recording/stop -d {} curl http://localhost:10001/recording/download --output recording.mp4 ``` +Note: the recording file is encoded into a H.264/MPEG-4 AVC video file. [QuickTime has known issues with playback](https://discussions.apple.com/thread/254851789?sortBy=rank) so please make sure to use a compatible media player! + ## Documentation This repo powers our managed [browser infrastructure](https://docs.onkernel.com). From 9ed9334a25e2cc6971d1dd5c96687b8fa2e15cb6 Mon Sep 17 00:00:00 2001 From: Sayan Samanta Date: Thu, 10 Jul 2025 18:02:05 -0700 Subject: [PATCH 5/5] fixes. explicit build step --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9a488609..fab2832b 100644 --- a/README.md +++ b/README.md @@ -147,8 +147,10 @@ You can use the embedded recording server to capture recordings of the entire sc For example: ```bash -cd /images/chromium-headful -IMAGE=kernel-docker ENABLE_WEBRTC=true ./run-docker.sh +cd images/chromium-headful +export IMAGE=kernel-docker +./build-docker.sh +WITH_KERNEL_IMAGES_API=true ENABLE_WEBRTC=true ./run-docker.sh # 1. Start a new recording curl http://localhost:10001/recording/start -d {}