pipwerks / scorm-api-wrapper

The pipwerks SCORM API Wrapper
http://pipwerks.com
362 stars 125 forks source link

add try/catch around accesses of window.API #5

Closed christianp closed 11 years ago

christianp commented 11 years ago

Firefox's cross-site scripting security throws a "permission denied" error when trying to access properties of the parent window, and it belongs to a different domain than the child. For example, if I have a page at mysite.com containing a link to a SCORM package at theirsite.com which opens in a new window, the SCORM wrapper loaded at theirsite.com will cause a "permission denied" error when it tries to find the API through window.parent. This code catches that error and adds it to the debug trace but otherwise fails silently, the same as if both pages are on the same domain and the API isn't present.

pipwerks commented 11 years ago

Thanks for the suggestion, but I don't see the merit.

SCORM courses are supposed to be launched in the same domain. Why would the course be launched from a different domain?

If the cross-domain issue occurs, communication will fail. Using try/catch to make it silent would not alert me to the failure. In this case, I'd want to see an error.

christianp commented 11 years ago

This came about because my packages are quite often used stand-alone, outside a SCORM environment. Rather than have two versions, one with SCORM code and one without, I just let the API wrapper decide if there's a SCORM API present, and act based on that. When the cross-domain error occurs because the wrapper tries to access a parent window I don't know about, I'd rather the wrapper swallows it than deal with it myself. But you're right, in the case when you expect there to be a SCORM API, you'd want an error.