Install
openclaw skills install my-play-music-from-ytPlay music on YouTube via browser automation with playwright-cli. Use when the user wants to: (1) play a specific song (e.g. 'play Money Money Money by ABBA') (2) play songs by an artist as a playlist or mix (e.g. 'play Jay Chou's songs') (3) play genre or mood-based music (e.g. 'play relaxing spa music', 'play 60s Chinese oldies') (4) control playback — next, pause, resume, stop, skip ad, change song, close the player. Also handles song/artist name corrections from voice transcription errors.
openclaw skills install my-play-music-from-ytThis skill controls a visible browser using playwright-cli to search and play YouTube music.
All actions follow snapshot → ref → action pattern. Never guess. Never assume.
-s=music_player
Every command must include it.
playwright-cli -s=music_player snapshot
Never click/fill without fresh refs.
click e123
fill e45 "text"
Never use CSS, XPaths, or assumptions.
--headed
Use headed by default unless the user explicitly requests headless.
After playback begins, do not block waiting. Continue responding normally.
--persistent
Always include --persistent when opening a new session. This saves the browser profile (cookies, localStorage, IndexedDB, cache) to disk, so login state survives session restarts.
Snapshots generated by playwright-cli may exist in two possible locations:
$WORKSPACE/.playwright-cli/ ← primary (search here first)~/.playwright-cli/ ← fallback when the workspace folder is emptyUse only these two folders unless the user explicitly authorizes a broader search.
If no .yml snapshots appear here, it is almost always MacOS permission-related. Ask the user to run:
playwright-cli open https://www.youtube.com --headed
This will trigger macOS system dialogs for:
Approve all to enable snapshot generation.
Note: On Windows and Linux, these permission dialogs do not apply. If snapshots are missing on those platforms, check that the browser launched correctly.
playwright-cli list
playwright-cli -s=music_player open https://www.youtube.com --headed --persistent
On any unexpected error, run playwright-cli list first to diagnose before retrying.
playwright-cli -s=music_player goto https://www.youtube.com
This reliably resets the page without closing the session.
Build the search query based on user intent:
| Intent | Query pattern | Example |
|---|---|---|
| Specific song | [Artist] [Song Title] | ABBA Money Money Money |
| Artist playlist | [Artist] | 周杰倫 |
| Genre / mood | [descriptor] music playlist | relaxing spa music playlist |
| Era-based | [era] [language/genre] playlist | 華語 60年代 老歌 playlist |
Search tips:
Voice transcription (ASR) and typo handling:
A clean search state avoids dropdown obstruction.
Perform the following every time before a new search:
"Clear search query" / "清除搜尋查詢" is present → click it.playwright-cli -s=music_player press Escape
playwright-cli -s=music_player goto https://www.youtube.com
Then snapshot again.
Snapshot → find:
combobox "搜尋" orcombobox "Search"Record its ref (e.g., e34).
playwright-cli -s=music_player fill <searchRef> "SEARCH TERM"
playwright-cli -s=music_player press Enter
Then snapshot immediately to avoid suggestion-panel obstruction.
Select result based on user intent:
link whose heading matches the song title."Mix - [Artist]" links or playlist links for continuous playback.For guidance on identifying YouTube result types, see ./references/youtube-guide.md.
Important: Do NOT click channel cards (e.g. link "Artist Name ... @handle•NNNK subscribers ..." / "Artist Name ... @handle•NNN萬位訂閱者 ..."). They navigate to the channel page, not music. Look for Mix or playlist results below them.
Click using its ref:
playwright-cli -s=music_player click eXYZ
If click is blocked:
press Escapegoto https://www.youtube.com and restart from Step 1.After clicking a result:
playwright-cli -s=music_player snapshot
Loop up to 4 iterations:
If you see:
button "Pause (k)" orbutton "Play (k)" (but video advancing)AND no ad indicators → playback is active → report song title to the user.
Any element whose label contains:
→ click it immediately.
Note: If the skip button is [disabled] (countdown not yet elapsed), do NOT click it — wait ~5 seconds instead (see step 3).
Then snapshot again. YouTube often plays two consecutive ads — always check for a second ad after skipping.
Wait 5 seconds:
playwright-cli -s=music_player eval "await new Promise(r=>setTimeout(r,5000))"
Then snapshot again and repeat from step 1.
Always snapshot first.
| Command | Action |
|---|---|
| Pause | click button "Pause (k)" |
| Resume / Play | click button "Play (k)" |
| Next | press Shift+n |
| Previous | press Shift+p |
| Change song | Start new search from Step 1 |
| Stop | playwright-cli -s=music_player close |
Keyboard shortcuts (reliable alternative when button refs are hard to locate):
k → play / pause
Shift+n → next track
Shift+p → previous track
m → mute / unmute
f → fullscreen toggle
j → rewind 10s
l → forward 10s
Usage: playwright-cli -s=music_player press <key>
playwright-cli -s=music_player goto https://www.youtube.com
→ restart from Step 1.
playwright-cli list shows no music_player.
Inform the user the browser was closed, then recreate session:
playwright-cli -s=music_player open https://www.youtube.com --headed --persistent
Because --persistent is used, the browser profile (including login state) is restored automatically. No need to log in again.
Snapshot → locate dismiss actions:
Click dismiss.
Snapshot → look for "No thanks", "不用了,謝謝", or a dismiss/close button → click to dismiss.
Snapshot shows "Video unavailable" or similar error.
playwright-cli -s=music_player go-back → snapshot → try the next result link.playwright-cli -s=music_player press PageDown → snapshot again.playwright-cli -s=music_player reload → snapshot.playwright-cli -s=music_player close → reopen and retry from Step 1.If the browser opens but login state is lost, or YouTube forces re-authentication:
To completely reset the profile (last resort):
playwright-cli -s=music_player close
playwright-cli -s=music_player delete-data
playwright-cli -s=music_player open https://www.youtube.com --headed --persistent