fix: Hls.cast dead code, double-patch interceptors, manifest URL patterns
CI / test (pull_request) Successful in 32s
CI / test (pull_request) Successful in 32s
Hls.cast() is a TypeScript identity cast in hls.js — returns input unchanged, NOT a reverse-lookup. Replaced with scanning video element properties for HLS instance references real players store as custom properties. Fixed double-patching bug in interceptors.js and expanded URL pattern matching to cover /hls/, /playlist/, /manifest/, .hlsvod paths. 83/83 tests pass, clean build (9 modules).
This commit is contained in:
1 parent
542c5786be
commit
3cf402d3c7
3 files changed
+90
-50
No files matched your search
+16
-17
@@ -34,6 +34,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Helper: check if a URL looks like an HLS manifest
|
||||
function isManifestUrl(url) {
|
||||
var u = url.toLowerCase();
|
||||
return u.includes('.m3u8') || u.includes('.hlsvod') ||
|
||||
u.includes('/hls/') || u.includes('/playlist') || u.includes('/manifest');
|
||||
}
|
||||
|
||||
// Helper: report manifest to content script via postMessage
|
||||
function reportManifest(url, source) {
|
||||
var resolved = resolveUrl(url);
|
||||
@@ -64,12 +71,7 @@
|
||||
XMLHttpRequest.prototype.send = function (_body) {
|
||||
if (this._goon_url && typeof this._goon_url === 'string') {
|
||||
var resolved = resolveUrl(this._goon_url);
|
||||
if (
|
||||
resolved &&
|
||||
(resolved.includes('.m3u8') ||
|
||||
resolved.includes('/playlist') ||
|
||||
resolved.includes('/manifest'))
|
||||
) {
|
||||
if (resolved && isManifestUrl(resolved)) {
|
||||
reportManifest(resolved, 'xhr');
|
||||
}
|
||||
}
|
||||
@@ -82,12 +84,7 @@
|
||||
var url = typeof resource === 'string' ? resource : resource && resource.url;
|
||||
if (url && typeof url === 'string') {
|
||||
var resolved = resolveUrl(url);
|
||||
if (
|
||||
resolved &&
|
||||
(resolved.includes('.m3u8') ||
|
||||
resolved.includes('/playlist') ||
|
||||
resolved.includes('/manifest'))
|
||||
) {
|
||||
if (resolved && isManifestUrl(resolved)) {
|
||||
reportManifest(resolved, 'fetch');
|
||||
}
|
||||
}
|
||||
@@ -95,8 +92,12 @@
|
||||
};
|
||||
|
||||
// 3. Intercept HLS.js loadSource (catches HLS.js instances)
|
||||
// Guard against double-patching: only wrap if the method hasn't been patched yet.
|
||||
var hlsPatched = false;
|
||||
function patchHlsPrototype() {
|
||||
if (typeof Hls === 'undefined') return;
|
||||
if (hlsPatched) return; // Already patched — skip
|
||||
|
||||
var originalLoadSource = Hls.prototype.loadSource;
|
||||
if (!originalLoadSource) return;
|
||||
|
||||
@@ -115,6 +116,7 @@
|
||||
return originalAttachMedia.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
hlsPatched = true;
|
||||
}
|
||||
|
||||
// Patch immediately if HLS is already defined
|
||||
@@ -124,7 +126,6 @@
|
||||
// Use a combination of:
|
||||
// 1. Longer polling window (30s instead of 3s) to catch lazy-loaded players.
|
||||
// 2. MutationObserver on <head> for new <script> tags — catches late hls.js loads.
|
||||
var hlsPatched = false;
|
||||
if (!hlsPatched) {
|
||||
var pollCount = 0;
|
||||
var maxPolls = 600; // poll for up to ~30s (50ms interval)
|
||||
@@ -132,9 +133,8 @@
|
||||
var pollHls = setInterval(function () {
|
||||
pollCount++;
|
||||
if (typeof Hls !== 'undefined' && !hlsPatched) {
|
||||
hlsPatched = true;
|
||||
patchHlsPrototype();
|
||||
clearInterval(pollHls);
|
||||
if (hlsPatched) clearInterval(pollHls);
|
||||
}
|
||||
if (pollCount >= maxPolls) clearInterval(pollHls);
|
||||
}, 50);
|
||||
@@ -154,9 +154,8 @@
|
||||
if (src.includes('hls') || src.includes('videojs') || src.includes('player')) {
|
||||
// Script tag loaded — check if Hls is now defined
|
||||
if (typeof Hls !== 'undefined' && !hlsPatched) {
|
||||
hlsPatched = true;
|
||||
patchHlsPrototype();
|
||||
observer.disconnect();
|
||||
if (hlsPatched) observer.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user