mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 06:50:01 -04:00
fix: 84 -> 92 on acid3
This commit is contained in:
parent
e9f4e59566
commit
4263feca61
6 changed files with 40 additions and 17 deletions
|
@ -7,7 +7,7 @@ import { rewriteCss, rewriteHtml, rewriteJs } from "../../shared";
|
||||||
export default function (client: ScramjetClient, self: typeof window) {
|
export default function (client: ScramjetClient, self: typeof window) {
|
||||||
const _nativeGetAttribute = self.Element.prototype.getAttribute;
|
const _nativeGetAttribute = self.Element.prototype.getAttribute;
|
||||||
const nativeSetAttribute = self.Element.prototype.setAttribute;
|
const nativeSetAttribute = self.Element.prototype.setAttribute;
|
||||||
const _nativeHasAttribute = self.Element.prototype.hasAttribute;
|
const nativeHasAttribute = self.Element.prototype.hasAttribute;
|
||||||
|
|
||||||
const attrObject = {
|
const attrObject = {
|
||||||
nonce: [self.HTMLElement],
|
nonce: [self.HTMLElement],
|
||||||
|
@ -158,8 +158,11 @@ export default function (client: ScramjetClient, self: typeof window) {
|
||||||
return ctx.return(null);
|
return ctx.return(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.fn.call(ctx.this, `scramjet-data-${name}`)) {
|
if (nativeHasAttribute.call(ctx.this, `scramjet-data-${name}`)) {
|
||||||
ctx.return(ctx.fn.call(ctx.this, `scramjet-data-${name}`));
|
const attrib = ctx.fn.call(ctx.this, `scramjet-data-${name}`);
|
||||||
|
if (attrib === null) return ctx.return("");
|
||||||
|
|
||||||
|
return ctx.return(attrib);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -209,6 +212,7 @@ export default function (client: ScramjetClient, self: typeof window) {
|
||||||
return unrewriteHtml(ctx.get());
|
return unrewriteHtml(ctx.get());
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
client.Proxy("Element.prototype.insertAdjacentHTML", {
|
client.Proxy("Element.prototype.insertAdjacentHTML", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
if (ctx.args[1])
|
if (ctx.args[1])
|
||||||
|
@ -292,6 +296,9 @@ export default function (client: ScramjetClient, self: typeof window) {
|
||||||
"Node.prototype.parentElement",
|
"Node.prototype.parentElement",
|
||||||
"Node.prototype.previousSibling",
|
"Node.prototype.previousSibling",
|
||||||
"Node.prototype.nextSibling",
|
"Node.prototype.nextSibling",
|
||||||
|
"Range.prototype.commonAncestorContainer",
|
||||||
|
"AbstractRange.prototype.endContainer",
|
||||||
|
"AbstractRange.prototype.startContainer",
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
get(ctx) {
|
get(ctx) {
|
||||||
|
@ -306,6 +313,22 @@ export default function (client: ScramjetClient, self: typeof window) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
client.Proxy(
|
||||||
|
[
|
||||||
|
"HTMLIFrameElement.prototype.getSVGDocument",
|
||||||
|
"HTMLObjectElement.prototype.getSVGDocument",
|
||||||
|
"HTMLEmbedElement.prototype.getSVGDocument",
|
||||||
|
],
|
||||||
|
{
|
||||||
|
apply(ctx) {
|
||||||
|
const document = ctx.call();
|
||||||
|
if (document) {
|
||||||
|
ctx.return(ctx.this.contentDocument);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
client.Proxy("Node.prototype.getRootNode", {
|
client.Proxy("Node.prototype.getRootNode", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
const n = ctx.call() as Node;
|
const n = ctx.call() as Node;
|
||||||
|
|
|
@ -30,6 +30,7 @@ export default function (client: ScramjetClient, self: typeof window) {
|
||||||
self.MutationObserver.prototype,
|
self.MutationObserver.prototype,
|
||||||
self.document,
|
self.document,
|
||||||
self.MouseEvent.prototype,
|
self.MouseEvent.prototype,
|
||||||
|
self.Range.prototype,
|
||||||
]) {
|
]) {
|
||||||
for (const prop in target) {
|
for (const prop in target) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -294,6 +294,7 @@ export function rewriteSrcset(srcset: string, meta: URLMeta) {
|
||||||
|
|
||||||
// Rewrite the URLs and keep the descriptors (if any)
|
// Rewrite the URLs and keep the descriptors (if any)
|
||||||
const rewrittenUrl = rewriteUrl(url.trim(), meta);
|
const rewrittenUrl = rewriteUrl(url.trim(), meta);
|
||||||
|
|
||||||
return descriptors.length > 0
|
return descriptors.length > 0
|
||||||
? `${rewrittenUrl} ${descriptors.join(" ")}`
|
? `${rewrittenUrl} ${descriptors.join(" ")}`
|
||||||
: rewrittenUrl;
|
: rewrittenUrl;
|
||||||
|
|
|
@ -46,15 +46,13 @@ export function rewriteUrl(url: string | URL, meta: URLMeta) {
|
||||||
|
|
||||||
if (base.startsWith("about:")) base = unrewriteUrl(self.location.href); // jank!!!!! weird jank!!!
|
if (base.startsWith("about:")) base = unrewriteUrl(self.location.href); // jank!!!!! weird jank!!!
|
||||||
const realUrl = tryCanParseURL(url, base);
|
const realUrl = tryCanParseURL(url, base);
|
||||||
if (realUrl) {
|
if (!realUrl) return url;
|
||||||
return (
|
|
||||||
location.origin +
|
return (
|
||||||
$scramjet.config.prefix +
|
location.origin +
|
||||||
$scramjet.codec.encode(realUrl.href)
|
$scramjet.config.prefix +
|
||||||
);
|
$scramjet.codec.encode(realUrl.href)
|
||||||
} else {
|
);
|
||||||
return url;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ export function rewriteWorkers(
|
||||||
script("shared");
|
script("shared");
|
||||||
str += `self.$scramjet.config = ${JSON.stringify($scramjet.config)};`;
|
str += `self.$scramjet.config = ${JSON.stringify($scramjet.config)};`;
|
||||||
script("client");
|
script("client");
|
||||||
console.log(str);
|
|
||||||
|
|
||||||
let rewritten = rewriteJs(js, url, meta);
|
let rewritten = rewriteJs(js, url, meta);
|
||||||
if (rewritten instanceof Uint8Array) {
|
if (rewritten instanceof Uint8Array) {
|
||||||
|
@ -31,7 +30,7 @@ export function rewriteWorkers(
|
||||||
|
|
||||||
str += rewritten;
|
str += rewritten;
|
||||||
|
|
||||||
dbg.log("Rewrite", type, str);
|
// dbg.log("Rewrite", type, str);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,13 +58,14 @@ export async function handleFetch(
|
||||||
dataurl = unrewriteBlob(dataurl);
|
dataurl = unrewriteBlob(dataurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
const response: Response = await fetch(dataurl, {});
|
const response: Partial<BareResponseFetch> = await fetch(dataurl, {});
|
||||||
|
const url = dataurl.startsWith("blob:") ? dataurl : "(data url)";
|
||||||
|
response.finalURL = url;
|
||||||
let body: BodyType;
|
let body: BodyType;
|
||||||
|
|
||||||
if (response.body) {
|
if (response.body) {
|
||||||
body = await rewriteBody(
|
body = await rewriteBody(
|
||||||
response,
|
response as BareResponseFetch,
|
||||||
client
|
client
|
||||||
? {
|
? {
|
||||||
base: new URL(new URL(client.url).origin),
|
base: new URL(new URL(client.url).origin),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue