Skip to content

Commit 8d5cfa5

Browse files
committed
[frontend] implement window.open proxy
1 parent 09a9bd8 commit 8d5cfa5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

frontend/src/browser.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,26 @@ export class Browser extends StatefulClass {
6969
frame.frame.addEventListener("load", (e) => {
7070
tab.url = frame.client.url.href;
7171
});
72+
let browser = this;
73+
7274
frame.addEventListener("contextInit", (ctx) => {
75+
ctx.client.Proxy("window.open", {
76+
apply(pctx) {
77+
let tab = browser.newTab("_blank");
78+
tab.frame.go(pctx.args[0]);
79+
80+
// this is a bit jank: we need the global proxy NOW, but it will only load naturally after a few seconds
81+
const realContentWindow = tab.frame.frame.contentWindow;
82+
// :(
83+
const ctor: any = ctx.client.constructor;
84+
// see open.ts
85+
const newclient = new ctor(realContentWindow);
86+
newclient.hook();
87+
88+
pctx.return(newclient.globalProxy);
89+
},
90+
});
91+
7392
const framedoc = ctx.window.document;
7493

7594
framedoc.addEventListener("contextmenu", (e) => {

0 commit comments

Comments
 (0)