Forum Discussion

BrandonGrant's avatar
BrandonGrant
Community Member
4 years ago

postMessage to iframe parent not received cross-domain scorm

I am trying to implement a cross-domain solution for hosting content separately from my LMS by using the postMessage api, but am unable to receive the messages on the parent page where the iframe is located.  I have a scormWrapper.js file that I have added to the lms directory of the articulate package and modified the index_lms.html file to include the scripts (right above the inclusion of the scormdriver.js file).  My wrapper includes the API for scorm and the required methods LMSInitialize() and so forth. 

A quick aside here I had to edit the scormdriver.js file in order to get the SCORM_GrabAPI method to work correctly, it searches for the API from the top down instead of bottom up which causes a cross-domain an error to be thrown, this seems like a known issue as there is a //TODO comment in the code saying it should be wrapped in try catch block.

Anyway I would assume that I would be able to use postMessage as follows in the

window.parent.postMessage("My Message", myDomain);

with a handler on the hosting page

window.addEventListener('message', function(event){

if (event.origin !== trustedOrigin)

    //Do something show the error;

//Do something with the message

}, false);

I can confirm that the listener is working as i've used postMessage from the parent window to send a message to itself.  Using the chrome dev tools to do some digging I can see that when I hit my postMessage in the wrapper the window.location.ancestorOrigins attribute has two entries, a url for the location of the SCO ie: https://s3-bucket-url.com and then the url for the lms ie: https://mylms.com  I thought maybe I just needed to go up another level to hit it and tried

window.parent.parent.postMessage("My Message", myDomain);

but that isn't reaching the handler either.  Wondering if anyone has any insight into what's happening here or how to access the parent of the iframe, I realize this is a bit of a niche case but figured this might be a good place to see if someone had a similar issue as cross-domain scorm issues seem to be fairly common.

 

1 Reply