You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

宿主页面与iframe中JupyterLite实例通信:代码传输失败问题

问题

无法从宿主页面向嵌入的JupyterLite iframe实例传输数据,尤其是代码内容。参考JupyterLite官方关于宿主页面管理的文档后,我参考JupyterLab代码编辑器API编写了一个插件(修改index.ts),但问题依旧没有解决。

插件代码
import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application';
import { IEditorServices } from '@jupyterlab/codeeditor';
import IReplService from '@jupyterlite/server-extension';

/**
 * Initialization data for the jupyterlab-iframe-bridge-example extension.
 */
const plugin: JupyterFrontEndPlugin<void> = {
  id: 'jupyterlab-iframe-bridge-example:plugin',
  autoStart: true,
  requires: [IEditorServices, IReplService],
  activate: (app: JupyterFrontEnd, editorServices: IEditorServices, replService: IReplService) => {
    console.log('JupyterLab extension jupyterlab-iframe-bridge-example is activated!');

    /* Incoming messages management */
    window.addEventListener('message', (event) => {
      if (event.data.type === 'from-host-to-iframe') {
        console.log('Code received in the iframe:', event.data.code);
        const editor = editorServices.activeEditor;
        if (editor) {
          editor.model.value.setText(event.data.code);
          editor.focus();
          replService.executeCode(event.data.code);
        }
      }
    });
  },
};

export default plugin;

内容的提问来源于stack exchange,提问作者GAUTAM SARAWAGI

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 12:23:12