forked from tpd94/CDRM-Extension
Fix Trusted Types violation in manifest interceptor injection, which fixes data not showing for YouTube DRM
This commit is contained in:
parent
889a4c63f3
commit
6e22837047
@ -70,9 +70,8 @@ function safeHeaderShellEscape(str) {
|
||||
|
||||
// Intercep network to find manifest
|
||||
function injectManifestInterceptor() {
|
||||
const script = document.createElement("script");
|
||||
script.textContent = `
|
||||
(function() {
|
||||
// Execute the interceptor code directly instead of injecting a script
|
||||
(function () {
|
||||
function isProbablyManifest(text = "", contentType = "") {
|
||||
const lowerCT = contentType?.toLowerCase() ?? "";
|
||||
const sample = text.slice(0, 2000);
|
||||
@ -87,13 +86,18 @@ function injectManifestInterceptor() {
|
||||
const isJsonManifest = sample.includes('"playlist"') && sample.includes('"segments"');
|
||||
|
||||
return (
|
||||
isHLSMime || isDASHMime || isSmoothMime ||
|
||||
isHLSKeyword || isDASHKeyword || isSmoothKeyword || isJsonManifest
|
||||
isHLSMime ||
|
||||
isDASHMime ||
|
||||
isSmoothMime ||
|
||||
isHLSKeyword ||
|
||||
isDASHKeyword ||
|
||||
isSmoothKeyword ||
|
||||
isJsonManifest
|
||||
);
|
||||
}
|
||||
|
||||
const originalFetch = window.fetch;
|
||||
window.fetch = async function(input, init) {
|
||||
window.fetch = async function (input, init) {
|
||||
const response = await originalFetch.apply(this, arguments);
|
||||
|
||||
try {
|
||||
@ -113,14 +117,24 @@ function injectManifestInterceptor() {
|
||||
});
|
||||
|
||||
const headerFlags = Object.entries(headersObj)
|
||||
.map(([key, val]) => '--add-headers "' + safeHeaderShellEscape(key) + ': ' + safeHeaderShellEscape(val) + '"')
|
||||
.map(
|
||||
([key, val]) =>
|
||||
'--add-headers "' +
|
||||
safeHeaderShellEscape(key) +
|
||||
": " +
|
||||
safeHeaderShellEscape(val) +
|
||||
'"'
|
||||
)
|
||||
.join(" ");
|
||||
|
||||
window.postMessage({
|
||||
window.postMessage(
|
||||
{
|
||||
type: "__MANIFEST_HEADERS__",
|
||||
url,
|
||||
headers: headerFlags
|
||||
}, "*");
|
||||
headers: headerFlags,
|
||||
},
|
||||
"*"
|
||||
);
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
@ -130,12 +144,12 @@ function injectManifestInterceptor() {
|
||||
const originalXHROpen = XMLHttpRequest.prototype.open;
|
||||
const originalXHRSend = XMLHttpRequest.prototype.send;
|
||||
|
||||
XMLHttpRequest.prototype.open = function(method, url) {
|
||||
XMLHttpRequest.prototype.open = function (method, url) {
|
||||
this.__url = url;
|
||||
return originalXHROpen.apply(this, arguments);
|
||||
};
|
||||
|
||||
XMLHttpRequest.prototype.send = function(body) {
|
||||
XMLHttpRequest.prototype.send = function (body) {
|
||||
this.addEventListener("load", function () {
|
||||
try {
|
||||
const contentType = this.getResponseHeader("content-type") || "";
|
||||
@ -146,8 +160,8 @@ function injectManifestInterceptor() {
|
||||
console.log("[Manifest][xhr]", this.__url, contentType);
|
||||
|
||||
const xhrHeaders = {};
|
||||
const rawHeaders = this.getAllResponseHeaders().trim().split(/\\r?\\n/);
|
||||
rawHeaders.forEach(line => {
|
||||
const rawHeaders = this.getAllResponseHeaders().trim().split(/\r?\n/);
|
||||
rawHeaders.forEach((line) => {
|
||||
const parts = line.split(": ");
|
||||
if (parts.length === 2) {
|
||||
xhrHeaders[parts[0]] = parts[1];
|
||||
@ -155,23 +169,30 @@ function injectManifestInterceptor() {
|
||||
});
|
||||
|
||||
const headerFlags = Object.entries(xhrHeaders)
|
||||
.map(([key, val]) => '--add-headers "' + safeHeaderShellEscape(key) + ': ' + safeHeaderShellEscape(val) + '"')
|
||||
.map(
|
||||
([key, val]) =>
|
||||
'--add-headers "' +
|
||||
safeHeaderShellEscape(key) +
|
||||
": " +
|
||||
safeHeaderShellEscape(val) +
|
||||
'"'
|
||||
)
|
||||
.join(" ");
|
||||
|
||||
window.postMessage({
|
||||
window.postMessage(
|
||||
{
|
||||
type: "__MANIFEST_HEADERS__",
|
||||
url: this.__url,
|
||||
headers: headerFlags
|
||||
}, "*");
|
||||
headers: headerFlags,
|
||||
},
|
||||
"*"
|
||||
);
|
||||
}
|
||||
} catch (e) {}
|
||||
});
|
||||
return originalXHRSend.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
`;
|
||||
document.documentElement.appendChild(script);
|
||||
script.remove();
|
||||
}
|
||||
|
||||
injectManifestInterceptor();
|
||||
|
@ -70,9 +70,8 @@ function safeHeaderShellEscape(str) {
|
||||
|
||||
// Intercep network to find manifest
|
||||
function injectManifestInterceptor() {
|
||||
const script = document.createElement("script");
|
||||
script.textContent = `
|
||||
(function() {
|
||||
// Execute the interceptor code directly instead of injecting a script
|
||||
(function () {
|
||||
function isProbablyManifest(text = "", contentType = "") {
|
||||
const lowerCT = contentType?.toLowerCase() ?? "";
|
||||
const sample = text.slice(0, 2000);
|
||||
@ -87,13 +86,18 @@ function injectManifestInterceptor() {
|
||||
const isJsonManifest = sample.includes('"playlist"') && sample.includes('"segments"');
|
||||
|
||||
return (
|
||||
isHLSMime || isDASHMime || isSmoothMime ||
|
||||
isHLSKeyword || isDASHKeyword || isSmoothKeyword || isJsonManifest
|
||||
isHLSMime ||
|
||||
isDASHMime ||
|
||||
isSmoothMime ||
|
||||
isHLSKeyword ||
|
||||
isDASHKeyword ||
|
||||
isSmoothKeyword ||
|
||||
isJsonManifest
|
||||
);
|
||||
}
|
||||
|
||||
const originalFetch = window.fetch;
|
||||
window.fetch = async function(input, init) {
|
||||
window.fetch = async function (input, init) {
|
||||
const response = await originalFetch.apply(this, arguments);
|
||||
|
||||
try {
|
||||
@ -113,14 +117,24 @@ function injectManifestInterceptor() {
|
||||
});
|
||||
|
||||
const headerFlags = Object.entries(headersObj)
|
||||
.map(([key, val]) => '--add-headers "' + safeHeaderShellEscape(key) + ': ' + safeHeaderShellEscape(val) + '"')
|
||||
.map(
|
||||
([key, val]) =>
|
||||
'--add-headers "' +
|
||||
safeHeaderShellEscape(key) +
|
||||
": " +
|
||||
safeHeaderShellEscape(val) +
|
||||
'"'
|
||||
)
|
||||
.join(" ");
|
||||
|
||||
window.postMessage({
|
||||
window.postMessage(
|
||||
{
|
||||
type: "__MANIFEST_HEADERS__",
|
||||
url,
|
||||
headers: headerFlags
|
||||
}, "*");
|
||||
headers: headerFlags,
|
||||
},
|
||||
"*"
|
||||
);
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
@ -130,12 +144,12 @@ function injectManifestInterceptor() {
|
||||
const originalXHROpen = XMLHttpRequest.prototype.open;
|
||||
const originalXHRSend = XMLHttpRequest.prototype.send;
|
||||
|
||||
XMLHttpRequest.prototype.open = function(method, url) {
|
||||
XMLHttpRequest.prototype.open = function (method, url) {
|
||||
this.__url = url;
|
||||
return originalXHROpen.apply(this, arguments);
|
||||
};
|
||||
|
||||
XMLHttpRequest.prototype.send = function(body) {
|
||||
XMLHttpRequest.prototype.send = function (body) {
|
||||
this.addEventListener("load", function () {
|
||||
try {
|
||||
const contentType = this.getResponseHeader("content-type") || "";
|
||||
@ -146,8 +160,8 @@ function injectManifestInterceptor() {
|
||||
console.log("[Manifest][xhr]", this.__url, contentType);
|
||||
|
||||
const xhrHeaders = {};
|
||||
const rawHeaders = this.getAllResponseHeaders().trim().split(/\\r?\\n/);
|
||||
rawHeaders.forEach(line => {
|
||||
const rawHeaders = this.getAllResponseHeaders().trim().split(/\r?\n/);
|
||||
rawHeaders.forEach((line) => {
|
||||
const parts = line.split(": ");
|
||||
if (parts.length === 2) {
|
||||
xhrHeaders[parts[0]] = parts[1];
|
||||
@ -155,23 +169,30 @@ function injectManifestInterceptor() {
|
||||
});
|
||||
|
||||
const headerFlags = Object.entries(xhrHeaders)
|
||||
.map(([key, val]) => '--add-headers "' + safeHeaderShellEscape(key) + ': ' + safeHeaderShellEscape(val) + '"')
|
||||
.map(
|
||||
([key, val]) =>
|
||||
'--add-headers "' +
|
||||
safeHeaderShellEscape(key) +
|
||||
": " +
|
||||
safeHeaderShellEscape(val) +
|
||||
'"'
|
||||
)
|
||||
.join(" ");
|
||||
|
||||
window.postMessage({
|
||||
window.postMessage(
|
||||
{
|
||||
type: "__MANIFEST_HEADERS__",
|
||||
url: this.__url,
|
||||
headers: headerFlags
|
||||
}, "*");
|
||||
headers: headerFlags,
|
||||
},
|
||||
"*"
|
||||
);
|
||||
}
|
||||
} catch (e) {}
|
||||
});
|
||||
return originalXHRSend.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
`;
|
||||
document.documentElement.appendChild(script);
|
||||
script.remove();
|
||||
}
|
||||
|
||||
injectManifestInterceptor();
|
||||
|
Loading…
x
Reference in New Issue
Block a user