Angular 4 app using IE 11, "Can't execute code from a freed script"

One solution is to set the variable isEnableCrossContextCheck to true, so that IE should run the code containing a try/catch block, which can handle the error.

        if (isEnableCrossContextCheck) {
            try {
                var testString = delegate.toString();
                if ((testString === FUNCTION_WRAPPER || testString == BROWSER_TOOLS)) {
                    nativeDelegate.apply(target, args);
                    return false;
                }
            }
            catch (error) {
                nativeDelegate.apply(target, args);
                return false;
            }
        }
        else {
            var testString = delegate.toString(); 
            if ((testString === FUNCTION_WRAPPER || testString == BROWSER_TOOLS)) {
                nativeDelegate.apply(target, args);
                return false;
            }
        }

This post shows how to to that:

Angular 4 put a global constant available to zone.js


Simply use the below code to resolve the zone.js errors in IE 11/EDGE versions. The following code has to be placed in the polyfills.ts :

if (document['documentMode'] || /Edge/.test(navigator.userAgent)) {
    (window as any).__Zone_enable_cross_context_check = true;
}

Make the config changes in above code based on your requirement


According to this thread the actual fix is to do nothing! This error only occurs when DevTools are open in IE, which basically means it only happens when you are looking for it. IE is just wonderful, isn't it?

Closing DevTools (as almost everyone will when viewing a website) will not cause this error to happen.

The above fixes can be applied for a testing or a development environment if needed, but ideally do not apply them to a production environment since it just adds some extra overhead that isn't needed.