diff --git a/src/client/client.ts b/src/client/client.ts index 6281849..09a50da 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -68,8 +68,10 @@ export class ScramjetClient { constructor(public global: typeof globalThis) { this.serviceWorker = this.global.navigator.serviceWorker; - if ("document" in self) { + if ("document" in global) { this.documentProxy = createDocumentProxy(this, global); + + global.document[SCRAMJETCLIENT] = this; } this.locationProxy = createLocationProxy(this, global); diff --git a/src/client/natives.ts b/src/client/natives.ts index 39e75d5..6f5eda6 100644 --- a/src/client/natives.ts +++ b/src/client/natives.ts @@ -1,3 +1,17 @@ export const nativeFunction = self.Function; export const nativeGetOwnPropertyDescriptor = self.Object.getOwnPropertyDescriptor; + +// descriptors +export const nativeDefaultViewGetter = nativeGetOwnPropertyDescriptor( + Document.prototype, + "defaultView" +)!.get!; +export const nativeContentDocumentGetter = nativeGetOwnPropertyDescriptor( + HTMLIFrameElement.prototype, + "contentDocument" +)!.get!; +export const nativeContentWindowGetter = nativeGetOwnPropertyDescriptor( + HTMLIFrameElement.prototype, + "contentWindow" +)!.get!; diff --git a/src/types.d.ts b/src/types.d.ts index 9301af7..1f3fac4 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -83,6 +83,11 @@ declare global { [SCRAMJETCLIENT]: ScramjetClient; } + interface HTMLDocument { + // should be the same as window + [SCRAMJETCLIENT]: ScramjetClient; + } + interface HTMLIFrameElement { // the event target belonging to an