Backport current patches from the stable branch
Also adds patchs to mitigate crash on tear down, that'll end up with
more meaningful Javascript backtraces.
Resolves: #1759876
Resolves: #1764311
Resolves: #1770535
Resolves: #1770539
Resolves: #1770540