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

Enable IFrame -> host messaging #9

Open
jtpio opened this issue Nov 19, 2024 · 0 comments
Open

Enable IFrame -> host messaging #9

jtpio opened this issue Nov 19, 2024 · 0 comments
Labels
question Further information is requested

Comments

@jtpio
Copy link
Collaborator

jtpio commented Nov 19, 2024

For the first version, the JupyterLab extension defines an API for accessing commands, and exposes it to the host page with Comlink's expose helper.

At some point in the future, it may be interesting to enable communication the other way around: the host exposes an API, and the extension is able to call it at any time during the application lifecycle.

Posting here some notes on how this could be achieved with the comlink API.

Host

const endpoint = Comlink.windowEndpoint(childWindow);
// sample host API
const hostApi = {
  async getCmds() {
    return ['command1', 'command2', 'command3'];
  }
};

Comlink.expose(hostApi, endpoint);

IFrame

const endpoint = windowEndpoint(self.parent);
const host = wrap(endpoint) as any; // TODO: fix typings?
const cmds = await host.getCmds();
console.log('Commands from host:', cmds);
@jtpio jtpio added the question Further information is requested label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant