Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add onLoad and onClose to iframe custom tab #890

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

Closed
wants to merge 4 commits into from

Conversation

posva
Copy link
Member

@posva posva commented May 22, 2025

to allow custom integrations with iframes without compromising on a high level API yet:

  addCustomTab({
    name: 'pinia-colada',
    title: 'Pinia Colada',
    icon: 'https://pinia-colada.esm.dev/logo.svg',
    view: {
      type: 'iframe',
      src: '/__pinia-colada-devtools',
      persistent: false,
      onLoad(iframeEl: HTMLIFrameElement) {
        iframeEl.onclose

      },
      onClose(iframeEl: HTMLIFrameElement) {
      },
    },
    category: 'modules',
  })

Copy link

netlify bot commented May 22, 2025

Deploy Preview for vue-devtools-docs canceled.

Name Link
🔨 Latest commit fbc83b6
🔍 Latest deploy log https://app.netlify.com/projects/vue-devtools-docs/deploys/682ef1725a563d0008587e9f

Copy link

pkg-pr-new bot commented May 22, 2025

Open in StackBlitz

@vue/devtools-applet

npm i https://pkg.pr.new/@vue/devtools-applet@890

@vue/devtools-core

npm i https://pkg.pr.new/@vue/devtools-core@890

@vue/devtools-api

npm i https://pkg.pr.new/@vue/devtools-api@890

@vue/devtools

npm i https://pkg.pr.new/@vue/devtools@890

@vue/devtools-kit

npm i https://pkg.pr.new/@vue/devtools-kit@890

vite-plugin-vue-devtools

npm i https://pkg.pr.new/vite-plugin-vue-devtools@890

commit: fbc83b6

@posva
Copy link
Member Author

posva commented May 22, 2025

This doesn't work yet because the callbacks are lost (probably during serialization). There should be some communication up but I don't know where it is. The iframe can be accessed even if it's nested (e.g. window['vue-devtools-iframe'].contentWindow.document.getElementsByTagName('iframe')[0]))

@webfansplz
Copy link
Member

This doesn't work yet because the callbacks are lost (probably during serialization). There should be some communication up but I don't know where it is. The iframe can be accessed even if it's nested (e.g. window['vue-devtools-iframe'].contentWindow.document.getElementsByTagName('iframe')[0]))

Oh, yep. We need to handle the communication. I'll handle it.

@webfansplz
Copy link
Member

Hi @posva , It's a lit be hard to pass the iframe instance to the user app side. If we use tab name instead of it, can it cover your use case? For example:

  addCustomTab({
    name: 'pinia-colada',
    title: 'Pinia Colada',
    icon: 'https://pinia-colada.esm.dev/logo.svg',
    view: {
      type: 'iframe',
      src: '/__pinia-colada-devtools',
      persistent: false,
      onLoad(name) {
       console.log(name) //  'pinia-colada',

      },
      onClose(name) {
        console.log(name) //  'pinia-colada',
      },
    },
    category: 'modules',
  })

@posva
Copy link
Member Author

posva commented May 24, 2025

Why is it hard? Are they cases where the iframe can't be transferred? I suppose the case with the standalone devtools doesn't work because the devtools are not created by the main document but that's fine: with time a more powerful approach will be document pip

Having access to the iframe element is needed to establish the communication between the two documents.

@webfansplz
Copy link
Member

webfansplz commented May 24, 2025

Why is it hard? Are they cases where the iframe can't be transferred? I suppose the case with the standalone devtools doesn't work because the devtools are not created by the main document but that's fine: with time a more powerful approach will be document pip

Having access to the iframe element is needed to establish the communication between the two documents.

That's because the current communication way design, which we have in devtools client <=> user vue app always pass through serialized data to support the vite plugin/standalone app/extension panel target.

image

@posva
Copy link
Member Author

posva commented May 24, 2025

Yeah, I see. That's unfortunate.
There should be some way of communicating between the iframe added by addCustomTab and the Vue app. It would make devtools so much more powerful. I think there is something like that in Nuxt Devtools but you know better than me 😆

In my Pinia Colada devtools I use the messaging API and a custom DuplexChannel based on MessageChannel to communicate between the two context but the API still requires the 2 contexts to be attached to the same document. In the end, I think antfu/birpc is more flexible than just emit/listen but not sure of what would be the communication channel

@posva posva closed this May 24, 2025
@webfansplz
Copy link
Member

Yeah, I see. That's unfortunate. There should be some way of communicating between the iframe added by addCustomTab and the Vue app. It would make devtools so much more powerful. I think there is something like that in Nuxt Devtools but you know better than me 😆

In my Pinia Colada devtools I use the messaging API and a custom DuplexChannel based on MessageChannel to communicate between the two context but the API still requires the 2 contexts to be attached to the same document. In the end, I think antfu/birpc is more flexible than just emit/listen but not sure of what would be the communication channel

Yeah. If we only consider iframe hosts, it would be relatively easy to implement, but things get more complex and difficult in browser extension or Electron environments. Vue DevTools currently uses the MessageChannel API for cross-window communication in separate window mode, which is pretty cool. The communication design is also based on antfu/birpc, making one-to-many communication simple and elegant.

@posva
Copy link
Member Author

posva commented May 27, 2025

Then maybe there should be a callback in the add custom tab function that allows remote procedures to the iframe. Or any other method of communicating between the main app and the iframe added to the devtools
Otherwise adding an iframe cannot do much beyond displaying some docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants