mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 22:40:01 -04:00
unrewriteBlob parity
This commit is contained in:
parent
dc0a2c6d12
commit
3100d07609
3 changed files with 22 additions and 8 deletions
|
@ -1,7 +1,12 @@
|
||||||
import { SCRAMJETCLIENT } from "../../symbols";
|
import { SCRAMJETCLIENT } from "../../symbols";
|
||||||
import { ScramjetClient } from "../client";
|
import { ScramjetClient } from "../client";
|
||||||
import { nativeGetOwnPropertyDescriptor } from "../natives";
|
import { nativeGetOwnPropertyDescriptor } from "../natives";
|
||||||
import { unrewriteUrl, htmlRules, unrewriteHtml } from "../../shared";
|
import {
|
||||||
|
unrewriteUrl,
|
||||||
|
htmlRules,
|
||||||
|
unrewriteHtml,
|
||||||
|
unrewriteBlob,
|
||||||
|
} from "../../shared";
|
||||||
import {
|
import {
|
||||||
rewriteUrl,
|
rewriteUrl,
|
||||||
rewriteCss,
|
rewriteCss,
|
||||||
|
@ -71,8 +76,8 @@ export default function (client: ScramjetClient, self: typeof window) {
|
||||||
["src", "data", "href", "action", "formaction"].includes(attr)
|
["src", "data", "href", "action", "formaction"].includes(attr)
|
||||||
) {
|
) {
|
||||||
if (element === HTMLMediaElement && value.startsWith("blob:")) {
|
if (element === HTMLMediaElement && value.startsWith("blob:")) {
|
||||||
let origin = new URL(value.substring("blob:".length));
|
// mediasource blobs cannot be handled in the service worker and must be sourced here
|
||||||
value = "blob:" + location.origin + origin.pathname;
|
value = unrewriteBlob(value);
|
||||||
} else {
|
} else {
|
||||||
value = rewriteUrl(value, client.meta);
|
value = rewriteUrl(value, client.meta);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { URLMeta, rewriteUrl } from "./url";
|
||||||
import { rewriteCss } from "./css";
|
import { rewriteCss } from "./css";
|
||||||
import { rewriteJs } from "./js";
|
import { rewriteJs } from "./js";
|
||||||
import { CookieStore } from "../cookie";
|
import { CookieStore } from "../cookie";
|
||||||
|
import { unrewriteBlob } from "../../shared";
|
||||||
|
|
||||||
export function rewriteHtml(
|
export function rewriteHtml(
|
||||||
html: string,
|
html: string,
|
||||||
|
@ -120,8 +121,6 @@ export const htmlRules: {
|
||||||
"image",
|
"image",
|
||||||
"iframe",
|
"iframe",
|
||||||
"source",
|
"source",
|
||||||
"video",
|
|
||||||
"audio",
|
|
||||||
"input",
|
"input",
|
||||||
"track",
|
"track",
|
||||||
],
|
],
|
||||||
|
@ -132,6 +131,17 @@ export const htmlRules: {
|
||||||
poster: ["video"],
|
poster: ["video"],
|
||||||
"xlink:href": ["image"],
|
"xlink:href": ["image"],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
fn: (value: string, meta: URLMeta) => {
|
||||||
|
if (value.startsWith("blob:")) {
|
||||||
|
// for media elements specifically they must take the original blob
|
||||||
|
// because they can't be fetch'd
|
||||||
|
return unrewriteBlob(value);
|
||||||
|
}
|
||||||
|
return rewriteUrl(value, meta);
|
||||||
|
},
|
||||||
|
src: ["video", "audio"],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
fn: () => null,
|
fn: () => null,
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
rewriteHtml,
|
rewriteHtml,
|
||||||
rewriteJs,
|
rewriteJs,
|
||||||
rewriteWorkers,
|
rewriteWorkers,
|
||||||
|
unrewriteBlob,
|
||||||
} from "../shared";
|
} from "../shared";
|
||||||
|
|
||||||
import type { URLMeta } from "../shared/rewriters/url";
|
import type { URLMeta } from "../shared/rewriters/url";
|
||||||
|
@ -53,9 +54,7 @@ export async function swfetch(
|
||||||
) {
|
) {
|
||||||
let dataurl = requesturl.pathname.substring(this.config.prefix.length);
|
let dataurl = requesturl.pathname.substring(this.config.prefix.length);
|
||||||
if (dataurl.startsWith("blob:")) {
|
if (dataurl.startsWith("blob:")) {
|
||||||
let origin = new URL(dataurl.substring("blob:".length));
|
dataurl = unrewriteBlob(dataurl);
|
||||||
dataurl = "blob:" + location.origin + origin.pathname;
|
|
||||||
console.log(dataurl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let response: Response = await fetch(dataurl, {});
|
let response: Response = await fetch(dataurl, {});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue