Skip to content

Commit 40ff086

Browse files
committed
[frontend] update tab title with real title
1 parent 9210149 commit 40ff086

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

frontend/src/browser.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ export class Browser extends StatefulClass {
6666
frame.frame.addEventListener("load", (e) => {
6767
tab.url = frame.client.url.href;
6868
});
69+
frame.addEventListener("contextInit", (e) => {
70+
const framedoc = frame.frame.contentDocument!;
71+
const head = framedoc.querySelector("head")!;
72+
const observer = new MutationObserver(() => {
73+
const title = framedoc.querySelector("title");
74+
if (title) {
75+
tab.title = title.textContent || "New Tab";
76+
} else {
77+
tab.title = "New Tab";
78+
}
79+
});
80+
observer.observe(head, {
81+
childList: true,
82+
subtree: true,
83+
});
84+
});
6985
use(tab.url).listen(() => {
7086
this.activetab = this.activetab;
7187
});

0 commit comments

Comments
 (0)