maybe this is could be a solution for you. getActiveObject() returns null if a group is selected and if a object is selected getAtctiveGroup() returns null as well. Just create a function that returns whatever is selected on the canvas.
function getSelection(){
return canvas.getActiveObject() == null ? canvas.getActiveGroup() : canvas.getActiveObject()
}
If you now replace all getActiveObject() with getSelection() calls in your code this should solve your problem. Hope this helps.