Skip to content

Commit 8e8953c

Browse files
committed
[frontend] inform chrome of page loads
1 parent da8579d commit 8e8953c

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

packages/chrome/src/IsolatedFrame.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ const methods = {
269269
}
270270

271271
const head = findhead(handler.root as Node as Element)!;
272-
head.children.unshift(new Element("script", { src: inject_script }));
272+
273+
// inject after the scramjet scripts and before the rest of the page
274+
head.children.splice(3, 0, new Element("script", { src: inject_script }));
273275
});
274276

275277
const fetchresponse = await handleFetch.call(
@@ -580,7 +582,6 @@ function pageContextItems(
580582
}
581583
const chromemethods: ChromeboundMethods = {
582584
titlechange: async (tab, { title, icon }) => {
583-
console.log("title changed...", tab, title, icon);
584585
if (tab) {
585586
if (title) {
586587
tab.title = title;
@@ -603,4 +604,15 @@ const chromemethods: ChromeboundMethods = {
603604
pageContextItems(tab!, msg)
604605
);
605606
},
607+
load: async (tab, { url }) => {
608+
if (!tab) return;
609+
console.log("URL", url);
610+
if (tab.history.justTriggeredNavigation) {
611+
// url bar was typed in, we triggered this navigation, don't push a new state since we already did
612+
tab.history.justTriggeredNavigation = false;
613+
} else {
614+
// the page just loaded on its own (a link was clicked, window.location was set)
615+
tab.history.push(new URL(url), undefined, false);
616+
}
617+
},
606618
};

packages/chrome/src/components/TabStrip.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ DragTab.style = css`
192192
flex-direction: column;
193193
gap: 0.1em;
194194
}
195+
.tooltip .title {
196+
overflow: hidden;
197+
white-space: nowrap;
198+
text-overflow: ellipsis;
199+
}
195200
.tooltip .hostname {
196201
font-size: 12px;
197202
}

packages/inject/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,13 @@ function setupContextMenu() {
107107

108108
setupTitleWatcher();
109109
setupContextMenu();
110+
111+
// inform chrome of the current url
112+
// will happen if you get redirected/click on a link, etc, the chrome will have no idea otherwise
113+
sendChrome("load", {
114+
url: client.url.href,
115+
});
116+
117+
console.log("sent load", client.url.href);
118+
119+
// console.log(client);

packages/inject/src/types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export type Chromebound = {
2929
icon?: string;
3030
},
3131
];
32+
load: [
33+
{
34+
url: string;
35+
},
36+
];
3237
};
3338

3439
export type Framebound = {

0 commit comments

Comments
 (0)