diff --git a/src/client/shared/blob.ts b/src/client/shared/blob.ts index a20a043..380058a 100644 --- a/src/client/shared/blob.ts +++ b/src/client/shared/blob.ts @@ -1,24 +1,21 @@ +import { rewriteBlob, unrewriteBlob } from "../../shared"; import { ScramjetClient } from "../client"; -const realf = fetch; export default function (client: ScramjetClient) { - client.Proxy("URL.revokeObjectURL", { - apply(ctx) { - ctx.return(undefined); - }, - }); - + // hide the origin from object urls from the page client.Proxy("URL.createObjectURL", { apply(ctx) { const url: string = ctx.call(); - // additional origin concealer. also you need this for youtube for some fucking reason - - const start = "blob:" + location.origin; - if (url.startsWith(start)) { - const id = url.substring(start.length); - ctx.return("blob:" + client.url.origin + id); + if (url.startsWith("blob:")) { + ctx.return(rewriteBlob(url, client.meta)); } else { ctx.return(url); } }, }); + + client.Proxy("URL.revokeObjectURL", { + apply(ctx) { + ctx.args[0] = unrewriteBlob(ctx.args[0]); + }, + }); } diff --git a/src/shared.ts b/src/shared.ts index ec4b8d1..e3ff37b 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -1,6 +1,6 @@ export const { util: { BareClient, ScramjetHeaders, BareMuxConnection }, - url: { rewriteUrl, unrewriteUrl }, + url: { rewriteUrl, unrewriteUrl, rewriteBlob, unrewriteBlob }, rewrite: { rewriteCss, unrewriteCss, diff --git a/src/shared/index.ts b/src/shared/index.ts index f1096b6..954e12e 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -1,4 +1,9 @@ -import { rewriteUrl, unrewriteUrl } from "./rewriters/url"; +import { + rewriteUrl, + unrewriteUrl, + rewriteBlob, + unrewriteBlob, +} from "./rewriters/url"; import { rewriteCss, unrewriteCss } from "./rewriters/css"; import { rewriteHtml, rewriteSrcset } from "./rewriters/html"; import { rewriteJs } from "./rewriters/js"; @@ -20,6 +25,8 @@ self.$scramjet.shared = { url: { rewriteUrl, unrewriteUrl, + rewriteBlob, + unrewriteBlob, }, rewrite: { rewriteCss, diff --git a/src/types.d.ts b/src/types.d.ts index f7828b3..c6d48fe 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,5 +1,10 @@ import { ScramjetController } from "./controller/index"; -import { rewriteUrl, unrewriteUrl } from "./shared/rewriters/url"; +import { + rewriteBlob, + rewriteUrl, + unrewriteBlob, + unrewriteUrl, +} from "./shared/rewriters/url"; import { rewriteCss, unrewriteCss } from "./shared/rewriters/css"; import { htmlRules, @@ -57,6 +62,8 @@ declare global { url: { rewriteUrl: typeof rewriteUrl; unrewriteUrl: typeof unrewriteUrl; + rewriteBlob: typeof rewriteBlob; + unrewriteBlob: typeof unrewriteBlob; }; rewrite: { rewriteCss: typeof rewriteCss;