url.pathname and node baseurl

This commit is contained in:
velzie 2024-08-31 15:41:18 -04:00
parent 70e0a684ae
commit 48052ab3fe
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F

View file

@ -31,6 +31,15 @@ export default function (client: ScramjetClient, self: typeof window) {
imagesrcset: [self.HTMLLinkElement], imagesrcset: [self.HTMLLinkElement],
}; };
const urlinterfaces = [
self.HTMLAnchorElement.prototype,
self.HTMLAreaElement.prototype,
];
const originalhrefs = [
nativeGetOwnPropertyDescriptor(self.HTMLAnchorElement.prototype, "href"),
nativeGetOwnPropertyDescriptor(self.HTMLAreaElement.prototype, "href"),
];
const attrs = Object.keys(attrObject); const attrs = Object.keys(attrObject);
for (const attr of attrs) { for (const attr of attrs) {
@ -67,6 +76,48 @@ export default function (client: ScramjetClient, self: typeof window) {
} }
} }
// note that href is not here
const urlprops = [
"protocol",
"hash",
"host",
"hostname",
"origin",
"pathname",
"port",
"search",
];
for (const prop of urlprops) {
for (const i in urlinterfaces) {
const target = urlinterfaces[i];
const desc = originalhrefs[i];
client.RawTrap(target, prop, {
get(ctx) {
let href = desc.get.call(ctx.this);
if (!href) return href;
const url = new URL(decodeUrl(href));
return url[prop];
},
});
}
}
client.Trap("Node.prototype.baseURI", {
get() {
const base = self.document.querySelector("base");
if (base) {
return new URL(base.href, client.url).href;
}
return client.url.href;
},
set() {
return false;
},
});
client.Proxy("Element.prototype.setAttribute", { client.Proxy("Element.prototype.setAttribute", {
apply(ctx) { apply(ctx) {
const [name, value] = ctx.args; const [name, value] = ctx.args;