8000 [messaging] How to communicate with an iFrame? · Issue #90 · aklinker1/webext-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
< 8000 template class="js-flash-template">

[messaging] How to communicate with an iFrame? #90

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

Open
christianlundberg opened this issue Mar 3, 2025 · 1 comment
Open

[messaging] How to communicate with an iFrame? #90

christianlundberg opened this issue Mar 3, 2025 · 1 comment

Comments

@christianlundberg
Copy link
christianlundberg commented Mar 3, 2025

The documentation says that we're supposed to use defineWindowMessaging in order to communicate with an iFrame, but since it's missing an example, I can't figure out what's missing, but I never seem to receive the message.

// content script
import { windowMessaging } from '@/windowMessaging';

export default defineContentScript({
  matches: ['<all_urls>'],

  main(ctx) {
    // Define the UI
    const ui = createIframeUi(ctx, {
      page: '/app.html',
      position: 'inline',
      anchor: 'body',
    });

    // Show UI to user
    ui.mount();

    setTimeout(() => {
      console.log('content: sending test');
      windowMessaging.sendMessage('test', undefined);
    }, 5000);
  },
});
// iframe
import { windowMessaging } from '@/windowMessaging';

windowMessaging.onMessage('test', () => {
  console.log('iframe: received test');
});
@aklinker1
Copy link
Owner
aklinker1 commented Mar 4, 2025

This is probably what you're looking for:

windowMessaging.sendMessage('test', "*");

If that doesn't work, I need more info. How are you loading that // iframe code into the iframe? Do the iframe and parent frame share the same domain?

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

No branches or pull requests

2 participants
0