Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross frame access (WIP) #88

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions modules/extensions/src/api/experimental/frame.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export function getAllFrames() {
if (!window) {
throw new Error("getAllFrames() can only be called in a browser");
}

if (!window.top) {
throw new Error("window.top does not exist");
}

let frames: Array<Window> = [];
for (let i = 0; i < window.top.frames.length; i++) {
let win = window.top.frames[i];
if (!win) {
continue;
}

frames.push(win);
}

return frames;
}

export function getExtensionFrames() {
let allFrames = getAllFrames();
return allFrames.map((f) => {
try {
if (f.location.href) {
return f;
}
} catch (e) {}
}).filter(Boolean);
}
1 change: 1 addition & 0 deletions modules/extensions/src/api/experimental/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * as auth from "./auth";
export * as editor from "./editor";
export * as frame from "./frame";
1 change: 1 addition & 0 deletions modules/extensions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function patchConsole() {
}

export async function init(args?: ReplitInitArgs): Promise<ReplitInitOutput> {
window.replit = replit;
if (extensionPort === null) {
throw new Error("Extension must be initialized in a browser context");
}
Expand Down