'message' event handler running in an iframe is not receiving the data sent by the `postMessage` call
See original GitHub issueWhat is your Scenario?
The SUT is using postMessage
from within a custom polymer web component to send data to a hidden iframe.
What is the Current behavior?
The message object that is received by the ‘message’ event handler has it’s data
field set to undefined
(as is it’s origin
field)
What is the Expected behavior?
The ‘message’ event handler running within the iframe should receive a message object with it’s data field set to the object that was supplied by the postMessage
call
Your complete app code (or attach your test files):
// polymer web component running in the parent top level window:
const configs = { configuration: 'some_important_value' };
this.$.auth.contentWindow.postMessage(configs, '*');
// (okta-auth.js) event handler for the posted message running in the iframe
window.addEventListener('message', function(e) {
// this line fails as `data` field is undefined
if(e.data.configuration) {
// do stuff with the e.data.configuration
}
});
// test file
import { Selector } from 'testcafe';
fixture`Test Welcome page`
.page`http://localhost:53660`;
test('When I navigate to the welcome page do I see the Application Gateway bar?', async t => {
await t
.wait(10000)
.typeText('#ClientID', 'P123456')
.click('#GoButton')
.typeText('#okta-signin-username', 'blah.blah@blah.com')
.typeText('#okta-signin-password', 'xxxxxxxx')
.click('#okta-signin-submit')
.wait(15000)
.expect(Selector('application-gateway-app').exists).ok();
});
Screenshots:
Your Environment details:
- node.js version: v10.15.3
- browser name and version: Chrome 75
- platform and version: Windows 10 1803
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Window.postMessage() - Web APIs | MDN
The window.postMessage() method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it ...
Read more >window.postMessage not working from iframe to parent ...
I've had exactly the same problem and have solved it by moving the "script" section above the iframe declaration.
Read more >Using JavaScript and window.postMessage() - In Plain English
window.postMessage() is a safe way to send messages between windows in different domains or origins. One can also post to an IFrame. The...
Read more >Cross-window communication - The Modern JavaScript Tutorial
To receive a message, the target window should have a handler on the message event. It triggers when postMessage is called (and targetOrigin ......
Read more >HTML5 window.postMessage - David Walsh Blog
If the destination window has changed, the message will not be sent. We've also created an event handler for receiving a message. It's...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @amal-architrave
To correctly raise an event you need to call 3 methods in sequence:
document.createEvent
event.initEvent
window.dispatchEvent
For more information, see the Creating and triggering events topic.
This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.