From 2d6683f904f09b29f1b435d5985d1c498fc6309b Mon Sep 17 00:00:00 2001 From: Grzegorz Mandziak Date: Fri, 13 Nov 2026 15:36:50 +0100 Subject: [PATCH 1/2] feat(providers): map media rewind, fast-forward and Tizen play-pause TV keys Samsung Tizen and LG webOS now accept tv-remote media-rewind (MediaRewind, 412) and media-fast-forward (MediaFastForward, 417) through a shared MEDIA_KEYS set in tv-cdp. Tizen also accepts media-play-pause (MediaPlayPause, 10252), which Samsung lists as its own remote key. webOS keeps refusing media-play-pause: it has separate Play (415) and Pause (19) key codes and no toggle. --- packages/provider-tizen/README.md | 15 +++++++------ packages/provider-tizen/src/keys.ts | 4 +++- packages/provider-tizen/src/runtime.test.ts | 24 +++++++++++++++++++++ packages/provider-webos/README.md | 15 +++++++------ packages/provider-webos/src/keys.ts | 3 ++- packages/provider-webos/src/runtime.test.ts | 24 +++++++++++++++++++++ packages/tv-cdp/src/index.ts | 2 +- packages/tv-cdp/src/keys.test.ts | 23 +++++++++++++++++++- packages/tv-cdp/src/keys.ts | 5 +++++ src/commands/schema/cli-help.ts | 3 ++- website/docs/docs/tizen.md | 6 ++++-- website/docs/docs/webos.md | 7 ++++-- 12 files changed, 110 insertions(+), 21 deletions(-) diff --git a/packages/provider-tizen/README.md b/packages/provider-tizen/README.md index 76feed07bb..079cd55b57 100644 --- a/packages/provider-tizen/README.md +++ b/packages/provider-tizen/README.md @@ -4,10 +4,11 @@ Drive web apps on Samsung Tizen TVs with [agent-device](https://agent-device.dev debug-launches the app over `sdb`, forwards its DevTools port, and drives the page over the Chrome DevTools Protocol: remote keys, pointer, text, snapshots, screenshots and console logs. -Status: experimental. Verified on a Samsung Smart Monitor M7 (Tizen 9.0, packaged build of a React -Native Web app): `connect`, `open`, `open --relaunch`, `snapshot -i`, `tv-remote` (directions, -select, back), `back`, `is focused`, `press`, `find ... click`, `hover`, `longpress`, `fill`, -`type`, `wait`, `scroll`, `screenshot`, `logs`, `apps`, `appstate`, `close`, `disconnect`. +Status: experimental. Verified on a Samsung Smart Monitor M7 (Tizen 9.0): `connect`, `open`, +`open --relaunch`, `snapshot -i`, `tv-remote` (directions, select, back, media-play-pause, +media-rewind, media-fast-forward), `back`, `is focused`, `press`, `find ... click`, `hover`, +`longpress`, `fill`, `type`, `wait`, `scroll`, `screenshot`, `logs`, `apps`, `appstate`, `close`, +`disconnect`. ## How it plugs in @@ -77,6 +78,7 @@ The TV is a leased device, so every command from `connect` to `disconnect` names | --- | --- | | `open` / `close` | `sdb shell 0 was_kill`, `sdb shell 0 debug` (prints the DevTools port), `sdb forward`, then CDP / `sdb shell 0 was_kill` | | `tv-remote press up/down/left/right/select/back`, `back` | `Input.dispatchKeyEvent` with the Samsung remote codes (Back = `XF86Back`, 10009) | +| `tv-remote press media-play-pause/media-rewind/media-fast-forward` | `Input.dispatchKeyEvent` with the Samsung media key codes (`MediaPlayPause` = 10252, `MediaRewind` = 412, `MediaFastForward` = 417) | | `appstate` | the attached app while its page is visible | | `apps` | `sdb shell 0 vd_applist`: user-installed apps with their titles | | `logs` | console calls, exceptions and browser log entries of the attached page, one line each | @@ -87,8 +89,9 @@ The TV is a leased device, so every command from `connect` to `disconnect` names | `type` | `Input.insertText` into the focused element | | `scroll` | `mouseWheel` at the centre of the scroll container or viewport, by the requested distance | -Not yet: system buttons (`home`, menu, volume, channel and media keys), `network dump`, `perf`, -`install` and `uninstall`, recording, URLs and deep links in `open`, `power`. +Not yet: system buttons (`home`, menu, volume and channel), `media-next` and `media-previous`, +`network dump`, `perf`, `install` and `uninstall`, recording, URLs and deep links in `open`, +`power`. ## Known limitations diff --git a/packages/provider-tizen/src/keys.ts b/packages/provider-tizen/src/keys.ts index aa524b3f05..8ce79a178b 100644 --- a/packages/provider-tizen/src/keys.ts +++ b/packages/provider-tizen/src/keys.ts @@ -1,6 +1,8 @@ -import { NAVIGATION_KEYS, type RemoteKeys } from '@agent-device/tv-cdp'; +import { MEDIA_KEYS, NAVIGATION_KEYS, type RemoteKeys } from '@agent-device/tv-cdp'; export const TIZEN_REMOTE_KEYS: RemoteKeys = { ...NAVIGATION_KEYS, back: { key: 'XF86Back', code: 'XF86Back', keyCode: 10009 }, + 'media-play-pause': { key: 'MediaPlayPause', code: 'MediaPlayPause', keyCode: 10252 }, + ...MEDIA_KEYS, }; diff --git a/packages/provider-tizen/src/runtime.test.ts b/packages/provider-tizen/src/runtime.test.ts index 6008195822..7311eab6bc 100644 --- a/packages/provider-tizen/src/runtime.test.ts +++ b/packages/provider-tizen/src/runtime.test.ts @@ -147,3 +147,27 @@ test('close kills the app on the leased TV', async () => { assert.equal(calls().at(-1), `-s 192.0.2.10:26101 shell 0 was_kill ${APP_ID}`); }); + +test('a remote button Tizen lacks is refused, listing the navigation, back and media buttons it accepts', async () => { + const { runtime } = await tizenRuntime(['192.0.2.10:26101']); + const allocated = await runtime.leaseLifecycle.allocate(lease('one')); + assert.ok(allocated); + + const press = runtime.getInteractor(allocated.device)!.tvRemote!('home'); + + await assert.rejects(press, (error: AppError) => { + assert.equal(error.code, 'UNSUPPORTED_OPERATION'); + assert.deepEqual(error.details?.supported, [ + 'up', + 'down', + 'left', + 'right', + 'select', + 'back', + 'media-play-pause', + 'media-rewind', + 'media-fast-forward', + ]); + return true; + }); +}); diff --git a/packages/provider-webos/README.md b/packages/provider-webos/README.md index 2864e9963e..b713ebc381 100644 --- a/packages/provider-webos/README.md +++ b/packages/provider-webos/README.md @@ -4,10 +4,10 @@ Drive web apps on LG webOS TVs with [agent-device](https://agent-device.dev). Th the app with the webOS CLI, opens the `ares-inspect` tunnel, and drives the page over the Chrome DevTools Protocol: remote keys, pointer, text, snapshots, screenshots and console logs. -Status: experimental. Verified on an LG 32LQ63006LA (webOS TV 22, dev build of a React Native Web -app): `connect`, `open`, `snapshot -i`, `snapshot -s`, `tv-remote` (directions, select, back), -`is focused`, `press @ref --settle`, `wait text`, `find`, `screenshot`, `logs`, `apps`, -`appstate`, `close`, `disconnect`. +Status: experimental. Verified on an LG 32LQ63006LA (webOS TV 22): `connect`, `open`, +`snapshot -i`, `snapshot -s`, `tv-remote` (directions, select, back, media-rewind, +media-fast-forward), `is focused`, `press @ref --settle`, `wait text`, `find`, `screenshot`, +`logs`, `apps`, `appstate`, `close`, `disconnect`. ## How it plugs in @@ -72,6 +72,7 @@ The TV is a leased device, so every command from `connect` to `disconnect` names | --- | --- | | `open` / `close` | `ares-launch` / `ares-launch --close`, then the `ares-inspect` tunnel | | `tv-remote press up/down/left/right/select/back`, `back` | `Input.dispatchKeyEvent` with the LG remote codes (Back = 461) | +| `tv-remote press media-rewind/media-fast-forward` | `Input.dispatchKeyEvent` with the LG media key codes (Rewind = 412, Fast-forward = 417) | | `appstate` | the attached app while its page is visible | | `apps` | `ares-install --listfull` | | `logs` | console calls, exceptions and browser log entries of the attached page, one line each | @@ -82,8 +83,10 @@ The TV is a leased device, so every command from `connect` to `disconnect` names | `type` | `Input.insertText` into the focused element | | `scroll` | `mouseWheel` at the centre of the scroll container or viewport, by the requested distance | -Not yet: system buttons (`home`, menu, volume, channel and media keys), `network dump`, `perf`, -`install` and `uninstall`, recording, URLs and deep links in `open`, `power`. +Not yet: system buttons (`home`, menu, volume and channel), `media-play-pause`, `media-next` and +`media-previous`, `network dump`, `perf`, `install` and `uninstall`, recording, URLs and deep links +in `open`, `power`. webOS has separate Play and Pause key codes and no play-pause toggle, so +`media-play-pause` is refused. ## Known limitations diff --git a/packages/provider-webos/src/keys.ts b/packages/provider-webos/src/keys.ts index 68004999e2..0408627ea1 100644 --- a/packages/provider-webos/src/keys.ts +++ b/packages/provider-webos/src/keys.ts @@ -1,6 +1,7 @@ -import { NAVIGATION_KEYS, type RemoteKeys } from '@agent-device/tv-cdp'; +import { MEDIA_KEYS, NAVIGATION_KEYS, type RemoteKeys } from '@agent-device/tv-cdp'; export const WEBOS_REMOTE_KEYS: RemoteKeys = { ...NAVIGATION_KEYS, back: { key: 'GoBack', code: 'BrowserBack', keyCode: 461 }, + ...MEDIA_KEYS, }; diff --git a/packages/provider-webos/src/runtime.test.ts b/packages/provider-webos/src/runtime.test.ts index 521ee6c68e..30da7f3f80 100644 --- a/packages/provider-webos/src/runtime.test.ts +++ b/packages/provider-webos/src/runtime.test.ts @@ -147,3 +147,27 @@ test('close stops the app with ares-launch --close', async () => { assert.deepEqual(recordedCalls(), [`ares-launch -d bedroom --close ${APP_ID}`]); }); + +test('media-play-pause is refused because webOS has no play-pause key, listing the buttons it accepts', async () => { + const runtime = await webosRuntime(); + const allocated = await runtime.leaseLifecycle.allocate(lease('lease-a')); + assert.ok(allocated); + + const press = runtime.getInteractor(allocated.device)!.tvRemote!('media-play-pause'); + + await assert.rejects(press, (error: unknown) => { + assert.ok(error instanceof AppError); + assert.equal(error.code, 'UNSUPPORTED_OPERATION'); + assert.deepEqual(error.details?.supported, [ + 'up', + 'down', + 'left', + 'right', + 'select', + 'back', + 'media-rewind', + 'media-fast-forward', + ]); + return true; + }); +}); diff --git a/packages/tv-cdp/src/index.ts b/packages/tv-cdp/src/index.ts index 68a60fc14b..b0480dbe36 100644 --- a/packages/tv-cdp/src/index.ts +++ b/packages/tv-cdp/src/index.ts @@ -2,7 +2,7 @@ import type { TvRuntimeHost } from './runtime.ts'; import type { TvPlatform } from './tv.ts'; export { listTargets, withTunnelRemoval } from './cdp.ts'; -export { NAVIGATION_KEYS, type RemoteKeys } from './keys.ts'; +export { MEDIA_KEYS, NAVIGATION_KEYS, type RemoteKeys } from './keys.ts'; export type { TvRuntimeHost } from './runtime.ts'; export type { PageTunnel, TvConnection } from './tv.ts'; diff --git a/packages/tv-cdp/src/keys.test.ts b/packages/tv-cdp/src/keys.test.ts index f4c1cc44ef..e7d00bae7a 100644 --- a/packages/tv-cdp/src/keys.test.ts +++ b/packages/tv-cdp/src/keys.test.ts @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; import { test } from 'vitest'; -import { keyEvents, NAVIGATION_KEYS } from './keys.ts'; +import { keyEvents, MEDIA_KEYS, NAVIGATION_KEYS } from './keys.ts'; test('select sends Enter with text so a focused button receives a click', () => { const [down, up] = keyEvents(NAVIGATION_KEYS.select); @@ -10,3 +10,24 @@ test('select sends Enter with text so a focused button receives a click', () => assert.equal(down!.text, '\r'); assert.equal(up!.type, 'keyUp'); }); + +test('rewind and fast-forward send the TV media key codes 412 and 417 without text', () => { + const media = (key: string, keyCode: number) => ({ + key, + code: key, + windowsVirtualKeyCode: keyCode, + nativeVirtualKeyCode: keyCode, + }); + + const rewind = keyEvents(MEDIA_KEYS['media-rewind']); + const fastForward = keyEvents(MEDIA_KEYS['media-fast-forward']); + + assert.deepEqual(rewind, [ + { ...media('MediaRewind', 412), type: 'keyDown' }, + { ...media('MediaRewind', 412), type: 'keyUp' }, + ]); + assert.deepEqual(fastForward, [ + { ...media('MediaFastForward', 417), type: 'keyDown' }, + { ...media('MediaFastForward', 417), type: 'keyUp' }, + ]); +}); diff --git a/packages/tv-cdp/src/keys.ts b/packages/tv-cdp/src/keys.ts index 75e01b516e..640b48519e 100644 --- a/packages/tv-cdp/src/keys.ts +++ b/packages/tv-cdp/src/keys.ts @@ -20,6 +20,11 @@ export const NAVIGATION_KEYS = { select: { key: 'Enter', code: 'Enter', keyCode: 13, text: '\r' }, } as const satisfies RemoteKeys; +export const MEDIA_KEYS = { + 'media-rewind': { key: 'MediaRewind', code: 'MediaRewind', keyCode: 412 }, + 'media-fast-forward': { key: 'MediaFastForward', code: 'MediaFastForward', keyCode: 417 }, +} as const satisfies RemoteKeys; + export function supportedRemoteButtons(keys: RemoteKeys): readonly TvRemoteButton[] { return Object.keys(keys) as TvRemoteButton[]; } diff --git a/src/commands/schema/cli-help.ts b/src/commands/schema/cli-help.ts index c9b6fad1d1..7f00828f82 100644 --- a/src/commands/schema/cli-help.ts +++ b/src/commands/schema/cli-help.ts @@ -229,9 +229,10 @@ Vega OS: Buttons: Examples: tv-remote longpress select; tv-remote press select --duration-ms 500. Syntax: tv-remote [press|longpress]