mirror of
https://github.com/moeru-ai/airi.git
synced 2026-11-29 19:03:29 +00:00
|
Some checks are pending
CI / Detect changes (push) Waiting to run
CI / Lint (push) Blocked by required conditions
CI / Build Test (stage-web) (push) Blocked by required conditions
CI / Build Test (stage-tamagotchi) (push) Blocked by required conditions
CI / Build Test (ui-playgrounds) (push) Blocked by required conditions
CI / Build Test (stage-tamagotchi-godot) (push) Blocked by required conditions
CI / Unit Test (others) (push) Blocked by required conditions
CI / Unit Test (api-server-1) (push) Blocked by required conditions
CI / Unit Test (api-server-2) (push) Blocked by required conditions
CI / Unit Test (stage-tamagotchi) (push) Blocked by required conditions
CI / Unit Test (stage-ui-1) (push) Blocked by required conditions
CI / Unit Test (stage-ui-2) (push) Blocked by required conditions
CI / Unit Test (push) Blocked by required conditions
CI / Type Check (others) (push) Blocked by required conditions
CI / Type Check (desktop) (push) Blocked by required conditions
CI / Type Check (web) (push) Blocked by required conditions
CI / Type Check (push) Blocked by required conditions
CI / Check Provenance (push) Blocked by required conditions
Cloudflare Pages (Auth UI) / Deploy - ui-server-auth (push) Waiting to run
Cloudflare Workers / Build - docs (push) Waiting to run
Cloudflare Workers / Deploy - stage-web (push) Blocked by required conditions
E2E Test - Tamagotchi (Linux) / X11 window render (Xvfb) (push) Waiting to run
E2E Test - Tamagotchi (Linux) / Wayland window render (weston headless) (push) Waiting to run
## Summary
When the user opens YouTube Shorts after a normal video in the same tab,
YouTube moves the previous video to a paused mini player. The extension
then described the mini player video, not the Short.
- The content script found the video with
`document.querySelector('video')`. That is the first video of the page,
and on Shorts it is the mini player.
- The title and channel came from the watch page heading. That heading
also belongs to the mini player video.
- Only the URL was the URL of the Short.
So the video context had the title, channel, subtitles, progress, and
paused state of the mini player video. The character said that the video
was paused and talked about the wrong video.
This PR adds `pickVideo` in `src/content/pick-video.ts`. A playing video
wins. Among the rest, the largest visible video wins. A video without
size is hidden and never wins. On Shorts pages, the content script does
not read the watch page heading or channel. The title then comes from
the page title of the Short.
The video elements on a Shorts page after a normal video, measured in
the browser console:
| Element | Size | State |
| --- | --- | --- |
| Mini player with the previous video | 400×225 | paused |
| The Short that plays | 315×560 | playing |
| Prepared player for the next Short | 0×0 | paused |
## Change map
| Module | Before | After | Description |
| --- | --- | --- | --- |
| `src/content/pick-video.ts` | None | `pickVideo` | Picks the video
that the user watches |
| `src/content/index.ts` video lookup |
`document.querySelector('video')` |
`pickVideo(document.querySelectorAll('video'))` | Used for the video
context and the vision frame |
| `src/content/index.ts` `findVideoTitle`, `findChannelName` | Read the
watch page heading on every YouTube page | Return nothing on Shorts
pages | The title falls back to the page title of the Short |
## Boundaries and risks
| Invariant or boundary | Failure mode | Protection | Evidence or gap |
| --- | --- | --- | --- |
| The context describes the video that the user watches | The first
video is a paused mini player | Playing video first, then the largest
visible video | Unit tests. Manual test on YouTube Shorts |
| Hidden players do not win | A hidden player is first in the DOM |
Videos without size are skipped | Unit test |
| A normal watch page keeps working | The only video is not picked | One
visible video is always picked | Unit test. Manual test on a watch page
|
| Cost of the lookup | `attach` runs on every DOM change and now reads
the size of each video | A page has few videos, three in the test above
| Not measured |
| The user plays the mini player on a Shorts page | The mini player
video wins, but the title is the title of the Short | None | Not
handled. Rare case |
| Channel on Shorts | The channel is unknown | Unknown is better than
the channel of the mini player video | I did not find a stable selector
for the Shorts channel |
## Verification
```text
pnpm -F @proj-airi/airi-plugin-web-extension test:run # 2 files, 7 tests passed
pnpm exec eslint plugins/airi-plugin-web-extension # passed, no output
pnpm --filter @proj-airi/airi-plugin-web-extension build:firefox # passed
```
Manual test (Zen Browser, temporary add-on from `.output/firefox-mv2`,
AIRI desktop v0.15.1): open a normal video, then open Shorts in the same
tab.
| Check | Before | After |
| --- | --- | --- |
| Live Preview title | Title of the mini player video | Title of the
Short |
| Live Preview channel | Channel of the mini player video | Unknown |
| Scroll to the next Short | Title does not change | Title changes |
| Ask the character about the video | "It is paused", about the mini
player video | The Short that plays |
Not verified:
- Bilibili and other sites. They use the same `pickVideo`. A page with
one visible video behaves as before.
- Chrome build.
This PR does not depend on #3461. They change different files.
I found this problem while testing #3461. I used an AI assistant to
trace the cause in the code and to write the changes. I reviewed the
changes and tested them myself.
---------
Co-authored-by: leafyy <wuqizq@outlook.com>
Co-authored-by: Neko <neko@ayaka.moe>
|
||
|---|---|---|
| .. | ||
| airi-plugin-bilibili-laplace | ||
| airi-plugin-claude-code | ||
| airi-plugin-game-chess | ||
| airi-plugin-web-extension | ||