This commit is contained in:
1 parent
b234c8dcae
commit
001cf146ee
10 files changed
+189
-217
No files matched your search
+28
-13
@@ -822,8 +822,11 @@ function playHls(video, manifestUrl, panel) {
|
||||
const config = Object.assign({}, HLS_CONFIG);
|
||||
|
||||
if (needProxy) {
|
||||
// Custom fetch loader that uses the service worker proxy for phncdn URLs.
|
||||
config.loader = window.Hls.DefaultConfig.loader || HlsLoader;
|
||||
// Override hls.js's default XHRLoader with our custom proxy loader.
|
||||
// Must NOT use DefaultConfig.loader || HlsLoader — the XHRLoader is always truthy,
|
||||
// so that would never apply HlsLoader. Set it directly on config (hls.js uses
|
||||
// the instance config, not DefaultConfig, when present).
|
||||
config.loader = HlsLoader;
|
||||
}
|
||||
|
||||
const hls = new window.Hls(config);
|
||||
@@ -859,21 +862,33 @@ function playHls(video, manifestUrl, panel) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Load hls.js from the extension bundle. Returns a Promise that resolves when ready.
|
||||
* We load from chrome.runtime.getURL() (extension origin) instead of a CDN to
|
||||
* avoid CSP blocks — sites like Pornhub restrict script-src to 'self', which
|
||||
* would block any cross-origin <script src> injection in the viewer window.
|
||||
* Load hlds.js (renamed from hls.js) from the extension bundle. Returns a Promise that resolves when ready.
|
||||
* Strategy: <script src="chrome-extension://.../hlds.js"> — esbuild minification is disabled so the
|
||||
* original ES5 UMD bundle preserves function expressions (no arrow functions), avoiding Chrome's
|
||||
* content-based ESM auto-detection that prevents window.Hls from registering globally.
|
||||
*/
|
||||
function loadHlsJs() {
|
||||
if (window.Hls && typeof window.Hls.isSupported === 'function') {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const hldsSrc = chrome.runtime.getURL('hlds.js');
|
||||
console.log('[goon-viewer] Trying script src:', hldsSrc);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if (window.Hls && window.Hls.isSupported) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
const script = document.createElement('script');
|
||||
script.src = chrome.runtime.getURL('hls.js');
|
||||
script.onload = () => resolve();
|
||||
script.onerror = () => reject(new Error('Hls.js bundle unavailable - rebuild the extension.'));
|
||||
script.src = hldsSrc;
|
||||
script.onload = () => {
|
||||
if (window.Hls && typeof window.Hls.isSupported === 'function') {
|
||||
console.log('[goon-viewer] hlds.js via script src OK, Hls.isSupported:', window.Hls.isSupported());
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error('hlds.js loaded but did not register global Hls'));
|
||||
}
|
||||
};
|
||||
script.onerror = () => {
|
||||
reject(new Error('hlds.js failed to load: resource not found or CSP blocked'));
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user