Backport 4610 to stable5

Backport #4610 to stable5

Please double check - js code shows some differences between master and stable5

@raghunayyar  @jancborchardt @karlitschek THX