H1b Master degree cap

My question is a person physically need to be in U.S.and (or) has to be on student visa (F1) to qualify for master cap for H1b visa?. As I’m planning to do Online master degree done from accredited Public or non-profitable U.S. University and I will be based outside U.S.

Is no one knows the answer?.