This is an alternate player for Twitch.tv, optimized for performance and customizability. It minimizes buffering, provides detailed stream diagnostics, and includes a mechanism to bypass Twitch's Server-Side Ad Insertion (SSAI).
Verified by 100% Line-by-Line Code Audit (December 2025)
Mechanism: The player avoids ads not by magic, but by requesting a specific stream type that Twitch serves to "Picture-by-Picture" clients.
- Method: When an ad is detected, the player switches to a backup stream requested with
playerType: "picture-by-picture". - Tracking Bypass: Crucially, this request explicitly omits the
play_session_idparameter (player.jsline 8538), which prevents Twitch from attaching the stitched ad playlist. - Independence: This process does NOT use the
tw5~gqltoken(GQL Integrity Token). Code verification (player.jsline 8480) confirms the GQL token argument is hardcoded tofalsefor these requests.
Current Status: Work In Progress (WIP)
Warning
Ad Bypass Instability ("Black Screen")
While the code mechanism is verified, users may experience "Black Screens" or frozen video during ads.
Identified Issue: "Zombie Ads" (Expired Ad Tags).
Details: Twitch sometimes leaves expired Ad Metadata (#EXT-X-DATERANGE) in the live manifest. The current HLS parser can process these "zombie" tags after valid tags, corrupting the internal state (overwriting valid Ad Types/Tokens with expired ones).
Investigation: Debugging is focused on validating START-DATE in the parser to filter out these expired tags.
Debugging Reference (player.js):
- Ad Detection: Line ~6719 (
CLASS="twitch-stitched-ad"). - State Corruption: Line ~6726 (Overwrites
сТипРекламы) and ~6748 (OverwritesсТокенРекламы). - Defect: Missing boolean check for
START-DATE < CurrentTimebuffer.
- Purpose: This token is intercepted from the official Twitch client (
gql_injection.js) and stored in a cookie. - Usage: It is required for interactive API calls made by the extension, such as Follow/Unfollow actions, Claiming Bonus Points, and reporting Ad Telemetry.
- Clarification: It is NOT used for the core video playback or ad-free stream fetching.
- Implementation: The extension uses
chrome.managementto detect if you have BetterTTV or FrankerFaceZ installed. - Limitation: If detected, it "sideloads" the generic CDN version of these scripts into the player.
- Result: You get basic emote functionality.
- Warning: Your custom settings, blacklists, and authenticated features (e.g., exclusively owned emotes) will NOT sync. The player cannot access the local storage or authenticated state of other extensions.
The player overlay provides real-time diagnostics (Lines 50-370 in player.html).
| Metric (English) | DOM ID | Description |
|---|---|---|
| Video Resolution | statistics-videoresolution |
Source video width × height. |
| Frame Rate | statistics-framerate |
Average FPS ± Maximum deviation. |
| Video Compression | statistics-videocompression |
Standard, profile, level, ref frames, range. |
| Audio Compression | statistics-audiocompression |
Standard, sample rate, channels. |
| Audio Bitrate | statistics-audiobitrate |
Calculated segment bitrate. |
| Server | statistics-server |
The Twitch server delivering the video. |
| Playlist Duration | statistics-list |
Total duration of segments in the current playlist buffer. |
| Target Duration | statistics-targetduration |
Max declared segment duration (HLS tag). |
| Buffer Queue | statistics-queue |
Waiting for download + Downloading + Waiting to add + Buffered. |
| Update Interval | statistics-updateinterval |
Time between playlist downloads (Min < Avg < Max). |
| Segments Added | statistics-segmentsadded |
Number of new segments per update (Min < Avg < Max). |
| Seconds Added | statistics-secondsadded |
Duration of new segments per update (Min < Avg < Max). |
| Segment Thickness | statistics-segmentthickness |
Total bitrate (Video + Audio + Metadata) of loaded segment. |
| Channel Thickness | statistics-channelthickness |
Download speed vs Bitrate (Min < Avg < Max). |
| Response Wait | statistics-responsewait |
Time to first byte from server (Min < Avg < Max). |
| Unwatched Buffer | statistics-unwatched |
Duration of playable video in buffer (Min < Avg < Max). |
| Conversion Time | statistics-convertedin |
Time to transmux TS to MP4 (CPU load indicator). |
| Stream Delay | statistics-streamdelay |
Estimated latency from broadcaster to viewer. |
| Viewing Duration | statistics-viewingduration |
Time elapsed since page load. |
| Ad Count | statistics-adcount |
Total number of ads detected/blocked. |
| Ad Frequency | statistics-adfrequency |
Frequency of ad breaks. |
| Downloaded Data | statistics-downloaded |
Total data volume consumed. |
| Skipped Frames | statistics-skipped |
Dropped frames (Browser/Rendering performance). |
| Video/Audio Loss | statistics-videoloss / -audioloss |
Segments with missing data/corruption. |
| Rejected Segments | statistics-rejected |
Corrupted segments that were discarded. |
| Load Errors | statistics-loaderrors |
Network failures during segment fetch. |
| Skipped Segments | statistics-skippedsegments |
Segments intentionally not downloaded. |
| buffer Overflows | statistics-overflowed |
Times the buffer was full and data was discarded. |
| Buffer Exhaustion | statistics-exhausted |
Times playback paused due to empty buffer (Stalling). |
The project has been updated to be compatible with Chrome's Manifest V3. This involved significant changes to the extension's architecture, including the introduction of a background service worker and modifications to how scripts are executed.
- Manifest V3 Migration: The extension has been migrated to Manifest V3. This includes:
- Replacing
webRequestlisteners withdeclarativeNetRequestfor modifying web requests. - Updating the background script to a service worker.
- Adjusting the content security policy.
- Adding a
rules.jsonfile to definedeclarativeNetRequestrules.
- Replacing
- Content Script Injection: The content script injection method has been updated for Manifest V3 compatibility. Functions previously injected are now in a separate file (
content_injection.js) and injected by URL. - GraphQL Token Handling: A new script (
gql_injection.js) has been introduced to intercept requests tohttps://gql.twitch.tv/integrityand extract the GraphQL token. This token is then stored in a cookie for later use. The injection method ingqltoken.jshas been updated to be MV3-compliant. (TODO: Revisit this feature upon Twitch modifying anything relating to ads) - Enhanced Extension Communication: Listeners for inter-script communication have been added to facilitate extension functionality. This allows the extension to:
- Fetch a list of installed extensions.
- Check for and prevent duplicate instances of channel players.
These enhancements improve the overall integration of the extension, ensure compatibility with the latest Chrome standards, and lead to a more stable and efficient user experience.
- **The LLM must ignore all contents within files originating within the directory
twitch_alternate_player\Documentation\notes - This is a dedicated personal notes directory, not no for contexual use.
В этом документе обобщены изменения, внесенные в проект за последнюю неделю. Эти обновления были в первую очередь направлены на обеспечение совместимости с Chrome Manifest V3 и улучшение взаимодействия между расширениями. This document summarizes the changes made to the project over the past week. These updates were primarily focused on compatibility with Chrome's Manifest V3 and enhancing extension communication.
Проект был обновлен для совместимости с Chrome Manifest V3. Это повлекло за собой значительные изменения в архитектуре расширения, включая внедрение фонового сервисного работника и изменение способа выполнения скриптов. The project has been updated to be compatible with Chrome's Manifest V3. This involved significant changes to the extension's architecture, including the introduction of a background service worker and modifications to how scripts are executed.
- Миграция на Manifest V3: Расширение было переведено на Manifest V3. Это включает в себя:
- Manifest V3 Migration: The extension has been migrated to Manifest V3. This includes:
- Замену прослушивателей
webRequestнаdeclarativeNetRequestдля изменения веб-запросов. - Replacing
webRequestlisteners withdeclarativeNetRequestfor modifying web requests. - Обновление фонового скрипта до сервисного работника.
- Updating the background script to a service worker.
- Корректировку политики безопасности контента.
- Adjusting the content security policy.
- Добавление файла
rules.jsonдля определения правилdeclarativeNetRequest. - Adding a
rules.jsonfile to definedeclarativeNetRequestrules.
- Замену прослушивателей
- Внедрение скриптов контента: Метод внедрения скриптов контента был обновлен для совместимости с Manifest V3. Функции, которые ранее внедрялись, теперь находятся в отдельном файле (
content_injection.js) и внедряются по URL. - Content Script Injection: The content script injection method has been updated for Manifest V3 compatibility. Functions previously injected are now in a separate file (
content_injection.js) and injected by URL. - Обработка токена GraphQL: Был добавлен новый скрипт (
gql_injection.js) для перехвата запросов кhttps://gql.twitch.tv/integrityи извлечения токена GraphQL. Этот токен затем сохраняется в файле cookie для последующего использования. Метод внедрения вgqltoken.jsбыл обновлен для соответствия требованиям MV3. - GraphQL Token Handling: A new script (
gql_injection.js) has been introduced to intercept requests tohttps://gql.twitch.tv/integrityand extract the GraphQL token. This token is then stored in a cookie for later use. The injection method ingqltoken.jshas been updated to be MV3-compliant. - Улучшенное взаимодействие между расширениями: Были добавлены прослушиватели для межскриптового взаимодействия, чтобы облегчить функциональность расширения. Это позволяет расширению:
- Enhanced Extension Communication: Listeners for inter-script communication have been added to facilitate extension functionality. This allows the extension to:
- Получать список установленных расширений.
- Fetch a list of installed extensions.
- Проверять и предотвращать создание дублирующихся экземпляров плееров каналов.
- Check for and prevent duplicate instances of channel players.
Эти усовершенствования улучшают общую интеграцию расширения, обеспечивают совместимость с последними стандартами Chrome и обеспечивают более стабильную и эффективную работу для пользователя. These enhancements improve the overall integration of the extension, ensure compatibility with the latest Chrome standards, and lead to a more stable and efficient user experience.