Effect of 3D magnetic perturbations on divertor conditions and detachment in tokamak and stellarator