Couldn't you use map.getTarget() instead of map.getViewport()? Note that getTarget is already exported by ol3.