宿主页面与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
相关产品推荐
相关产品推荐

