Skip to content
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

[BUG] IE11 -> Can't execute code from a freed script #31723

Closed
lifaon74 opened this issue Oct 20, 2017 · 39 comments
Closed

[BUG] IE11 -> Can't execute code from a freed script #31723

lifaon74 opened this issue Oct 20, 2017 · 39 comments
Assignees
Labels
area: zones P4 A relatively minor issue that is not relevant to core functions
Milestone

Comments

@lifaon74
Copy link

Context:

  • angular 5.0.0-rc3
  • zone.js 0.8.18
  • IE 11

I tried to update from zone 0.8.4 (current official angular 5 tutorials version) to 0.8.18, and get at some point with IE 11 the following error: Can't execute code from a freed script. This is a really imprecise error, that I didn't manage to find the origin but is due for sure from zone.js.

EDIT: after testing => appear from 0.8.12 (working) to 0.8.13 (no more working on IE 11)

@JiaLiPassion
Copy link
Contributor

@lifaon74 , could you provide a reproduce sample ?
or you can try to add following code in index.html before loading zone.js

<script>
__Zone_enable_cross_context_check = true;
</script>

to see the result.

@lifaon74
Copy link
Author

lifaon74 commented Oct 20, 2017

I took the example from https://github.com/mgechev/angular-seed , and updated to angular 5 and zone.js 0.8.18. I added you code and this worked ! Do you have detailed informations of what does this module (https://github.com/angular/zone.js/blob/master/MODULE.md) ? And idea why does it works on chrome but not on IE ?

Thanks to you.

EDIT 1 : the error is in zone.js inside checkIEAndCrossContext at line 2747
EDIT 2 : the bug is sometimes hard to reproduce as it does not append everytime

@JiaLiPassion
Copy link
Contributor

@lifaon74 , glad to help, and __Zone_enable_cross_context_check this flag will enable some additional error check to IE, in IE, sometimes DeveloperTools will also register eventListeners which will cause some weird exceptions.

@ganeshkbhat
Copy link

Happening to me in edge also. Using the latest cli 1.5.4

@falcopr
Copy link

falcopr commented Dec 14, 2017

@lifaon74 While analyzing the migration of AngularJS to Angular 5 we came across the same problem you mentioned here with zone.js 0.8.18 in IE11. Downgrading it to 0.8.12 does not throw the exception anymore. Thank you for mentioning this workaround.

@JiaLiPassion
Copy link
Contributor

@ganeshkbhat, @falcoprescher , could you guys try to add

<script>
__Zone_enable_cross_context_check = true;
</script>

in index.html before loading zone.js?

@falcopr
Copy link

falcopr commented Dec 14, 2017

@JiaLiPassion Setting this flag works which you suggested on the 20th October 2017.
Is this a fix or a workaround?

@JiaLiPassion
Copy link
Contributor

@falcoprescher , this is a fix and it should be better documented.
in old version, this flag is true by default, but it will have performance impact, so in recent version it has been changed to false, only in IE and some use cases it need to be set to true.

I will add document and better setting method later.

@falcopr
Copy link

falcopr commented Dec 14, 2017

@JiaLiPassion Thank you for the information. I am also considering disabling this flag in production mode via our webpack configuration.

webpack.config.js

new webpack.DefinePlugin({
    ...
    // Needs to be set for zone.js so it does not throw an exception in IE11 while being in developer tools
    // https://github.com/angular/zone.js/issues/933
    'zoneEnableCrossContextCheck': this.isDevMode ? 'true' : 'false'
}));

app.base.ts

import './app.globals.ts';
import 'zone.js';
...

app.globals.ts

declare let zoneEnableCrossContextCheck: boolean;
(<any>window).__Zone_enable_cross_context_check = zoneEnableCrossContextCheck;

@JiaLiPassion
Copy link
Contributor

@falcoprescher , thank you for the configuration idea!

@fuerst
Copy link

fuerst commented Jan 12, 2018

How can that be configured in an Angular CLI generated project?

@alexciesielski
Copy link

alexciesielski commented Jan 20, 2018

Also having this problem in IE11, how to configure this in angular cli?

@JiaLiPassion
Copy link
Contributor

JiaLiPassion commented Jan 21, 2018

@fuerst, @ciesielskico, you can just add the following line in polyfill.ts before loading zone.js.

(window as any).__Zone_enable_cross_context_check = true;
import 'zone.js/dist/zone';  // Included with Angular CLI.

@shcallaway
Copy link

shcallaway commented Jan 23, 2018

The code above produces a compiler error for me:

ERROR in src/polyfills.ts(58,1): error TS2304: Cannot find name '__Zone_enable_cross_context_check'.

I feel like I am missing something here...

@JiaLiPassion
Copy link
Contributor

@shcallaway , oh, sorry, please modify it to

(window as any).__Zone_enable_cross_context_check = true;
import 'zone.js/dist/zone';  // Included with Angular CLI.

kevinkuszyk referenced this issue in kevinkuszyk/angular-ie-freed-script-error Jan 26, 2018
@kevinkuszyk
Copy link

I'm seeing this intermittently even after adding the fix mentioned above.

I've pushed a sample repro at kevinkuszyk/angular-ie-freed-script-error which shows both this and #1001.

@danail-vasilev
Copy link

Hi @kevinkuszyk, can you try to set the property not in the polyfills file but directly in the index.html file? In my project when I set it in the index.html it is not reproducible but when it is set in the polyfills it doesn't take effect.
Thanks !

@JiaLiPassion
Copy link
Contributor

@danail-vasilev ,
there will be websocket to connect angular web app with angular dev server, and every time refresh IE page, there will be a new web socket was created.

and in IE, the maximum websocket connections are 6 by default, https://msdn.microsoft.com/ja-jp/library/ee330736%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396.
so error occurs, you can change the number by modify the registry.

\HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_WEBSOCKET_MAXCONNECTIONSPERSERVER
and add a key, iexplore.exe(REG_DWORD) modify the value to 2~128.

I just modify to 50, and the error gone.

@kevinkuszyk
Copy link

Thanks @danail-vasilev, putting the fix in the index.html as suggested by @JiaLiPassion above seems to fix it.

@jochenhebbrecht
Copy link

jochenhebbrecht commented Apr 13, 2018

Hi all,

The fixes I see above always set the value __Zone_enable_cross_context_check to true for kind of browser. I think it should only do it for Internet Explorer, no?
What are the consequences if the value is 'true' in for example Google Chrome / Mozilla Firefox?

Jochen

@JiaLiPassion
Copy link
Contributor

@jochenhebbrecht , the flag will try to catch all error when access the event handler. So it may also have impact in Chrome/firefox such as chrome/firefox extension code involved. There was an issue in firefox 52 which is try to access event handler in main page from firefox extension. With this flag, the issue was resolved.

So if you have the specified issue, I may be able to help you to see whether the flag will help.

@jochenhebbrecht
Copy link

Hi @JiaLiPassion ,

Thanks for your very fast feedback! :-)
So I conclude it's OK to put the flag for any kind of browser. Any plans for taking this up in a next release? (so you don't need to add the line)

Jochen

@kylecordes
Copy link

This is what I was wondering also - could this bug report be interpreted as a feature request, that Zone "just work" across browsers (including IE)?

@JiaLiPassion
Copy link
Contributor

@jochenhebbrecht , because this flag will basically impact IE/Edge developer tools, so it will not be true by default ( set to true will have some performance impact for addEventListener call). you can set it to true if you have such kind of use case.

@jochenhebbrecht
Copy link

@JiaLiPassion what do you mean with: it will have impact on IE/Edge developer tools? It seems to be working fine when put to true? The developer tools still work?
In the second part of your reply, your stating putting the value to true will impact the performance. You mean: it will work more slowly when put to true? If that's the case, then the value should be false when rendering in Google Chrome/Mozilla Firefox.

@JiaLiPassion
Copy link
Contributor

@jochenhebbrecht , yes, everything will work if you set it to true. enable the flag will cause an additional try/catch and toString operation when you call addEventListener. so it will be a little performance impact when you call addEventListener, the behavior is the same.

And the reason don't want to set it to true by default even in IE because it only impact some of the developer tools , so it only impact development mode, and in the new version of angular/cli generated project, you can find the following code in src/polyfills.ts.

 /*
 * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
 * with the following flag, it will bypass `zone.js` patch for IE/Edge
 */
// (window as any).__Zone_enable_cross_context_check = true;

you can open the comment when you in development mode and comment it when you want to build in production mode.

@jochenhebbrecht
Copy link

jochenhebbrecht commented Apr 14, 2018

Thanks @JiaLiPassion !
I can confirm the line is not needed when the developer tools are not open in IE.

@ojemuyiwa
Copy link

ojemuyiwa commented Jun 5, 2018

Thanks so much @JiaLiPassion

Added only for IE and Edge using the below in pollyfills.ts and it works a charm

/*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
*/
//(window as any).__Zone_enable_cross_context_check = true;
if (document['documentMode'] || /Edge/.test(navigator.userAgent)) {
    (window as any).__Zone_enable_cross_context_check = true;
}

@maxmumford
Copy link

maxmumford commented Aug 29, 2018

I seem to get this error in IE11 while dev tools are open, regardless of whether or not JiaLiPassion's fix is applied. Closing dev tools makes the web app load again....... gotta love IE

@mleibman
Copy link

Has this been documented?
This thread is a bit hard to parse, so please correct me if I'm wrong:

  • This fixes an intermittent issue in IE11 that manifests only if the dev tools are open.
  • Enabling it in production is not recommended since it has performance overhead.
  • Enabling it during development or for unit tests is fine.

@stcoder
Copy link

stcoder commented Apr 29, 2019

Try to specify the version of IE in .browserlistrc, helped me.

### Supported Browsers

> 1%
last 2 versions
iOS > 7
ie 6-11

@Deepakm1051
Copy link

Deepakm1051 commented Jul 4, 2019

@JiaLiPassion

  1. I have added the following code in index.html. It does not work for me still the application is keep loading in IE. My developer tool was closed.

<script>
__Zone_enable_cross_context_check = true;
</script>

  1. I tried this approach also

In pollyfills.ts, uncommented the following line

(window as any).__Zone_enable_cross_context_check = true;

  1. The max websocket per server connection was set to 50 for Internet explorer

could you help me to resolve this issue?

Thanks in advance.

@JiaLiPassion JiaLiPassion transferred this issue from angular/zone.js Jul 21, 2019
@JiaLiPassion JiaLiPassion self-assigned this Jul 21, 2019
@ngbot ngbot bot added this to the needsTriage milestone Jul 21, 2019
@JiaLiPassion
Copy link
Contributor

@Deepakm1051, please provide a reproduce repo, thanks.

@Deepakm1051
Copy link

Deepakm1051 commented Jul 22, 2019

@JiaLiPassion we found this issue bcoz of window.addEventListener().

window.addEventListener("storage", checkTabs);

function checkTabs(ev) {
if (ev.storageArea == localStorage) {
let token = localStorage.getItem('userToken');
if (token == undefined || token == null) {
window.location.href = ev.url;
}
}
}

We have a requirement like

  1. open two tabs and log in with the same account
  2. logout in one tab and another tab also should logout automatically.
    Thanks.

Commenting the code does not give any problem

@eafiontzi
Copy link

In Angular 8, the polyfills.ts file specifically explains to create a new file in the same directory as polyfills.ts and add the zone checks in there. Then import it to the polyfills.ts file before zone.js.
Quote from the file:
`/**

  • By default, zone.js will patch all possible macroTask and DomEvents
  • user can disable parts of macroTask/DomEvents patch by setting following flags
  • because those flags need to be set before zone.js being loaded, and webpack
  • will put import in the top of bundle, so user need to create a separate file
  • in this directory (for example: zone-flags.ts), and put the following flags
  • into that file, and then add the following code before importing zone.js.
  • import './zone-flags.ts';
  • The flags allowed in zone-flags.ts are listed here.
  • The following flags will work for all browsers.
  • (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
  • (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
  • (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
  • in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
  • with the following flag, it will bypass zone.js patch for IE/Edge
  • (window as any).__Zone_enable_cross_context_check = true;

*/`

@gayankasun
Copy link

I couldn't find such a registry entry for Latest IE on Windows 10

@danielehrhardt
Copy link

Same Issue here

@jelbourn jelbourn added the P4 A relatively minor issue that is not relevant to core functions label Oct 1, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Oct 1, 2020
@AndrewKushnir
Copy link
Contributor

Closing this ticket, since the reported problem was only present in IE11 and Angular no longer supports IE.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: zones P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

No branches or pull requests