Skip to content

Commit e934575

Browse files
committed
[chrome] add support for blob urls when isolated
1 parent 34a2090 commit e934575

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

packages/chrome/src/IsolatedFrame.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,23 @@ function makeController(url: URL): Controller {
321321
return (await fetch(dataUrl)) as BareResponseFetch;
322322
},
323323
async fetchBlobUrl(blobUrl: string) {
324-
console.log("uuhhh");
325-
return new Response("hawk tuah") as BareResponseFetch;
324+
// find a random tab under this controller
325+
console.log("FETCHUBG BLOB");
326+
const tab = browser.tabs.find(
327+
(tab) => tab.frame.controller === controller
328+
);
329+
if (!tab) throw new Error("No tab found for blob fetch (?)");
330+
const response = await sendFrame(tab, "fetchBlob", blobUrl);
331+
console.log("FETCHED BLOB", response);
332+
333+
let headers = new Headers();
334+
headers.set("Content-Type", response.type);
335+
336+
return {
337+
headers,
338+
body: response.body,
339+
status: 200,
340+
} as unknown as BareResponseFetch;
326341
},
327342
});
328343

@@ -344,6 +359,7 @@ function makeController(url: URL): Controller {
344359

345360
export class IsolatedFrame {
346361
frame: HTMLIFrameElement;
362+
controller: Controller | null = null;
347363
constructor() {
348364
this.frame = document.createElement("iframe");
349365
}
@@ -357,6 +373,7 @@ export class IsolatedFrame {
357373
controller = makeController(url);
358374
}
359375
await controller.ready;
376+
this.controller = controller;
360377

361378
const prefix = controller.prefix;
362379

packages/inject/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ export const methods: FrameboundMethods = {
1919
const popStateEvent = new PopStateEvent("popstate", { state });
2020
window.dispatchEvent(popStateEvent);
2121
},
22+
async fetchBlob(url) {
23+
const response = await fetch(url);
24+
const ab = await response.arrayBuffer();
25+
return {
26+
body: ab,
27+
contentType:
28+
response.headers.get("Content-Type") || "application/octet-stream",
29+
};
30+
},
2231
};
2332

2433
(globalThis as any).$injectLoad = (init: InjectScramjetInit) => {

packages/inject/src/types.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ export type Framebound = {
6666
title: string;
6767
},
6868
];
69+
fetchBlob: [
70+
string,
71+
{
72+
body: ArrayBuffer;
73+
contentType: string;
74+
},
75+
];
6976
};
7077

7178
export type InjectScramjetInit = {

0 commit comments

Comments
 (0)