You CAN APPLY ONLINE! The agents at IRCC did confirm this. However, you apply online to the embassy in the country you intend on visiting. You could wait for approval and then travel. The passport will then be have to sent to the embassy for visa stamping.
CHECK CAREFULLY!
You wrote "YOU CAN APPLY ONLINE." Perhaps true in the sense of technically feasible. That doesn't mean it's allowed.
-For the form that can be downloaded, yes, you are given the option to mark that you are in Canada ;
-but, the instructions for applying for a PRTD say that you should only apply for a PRTD if you are
outside Canada - and then repeat this by saying that if you are
in Canada, you should apply for a PR card (eg replacement or renewal).
This would seem contradictory BUT for the fact that the same form is used for both PR cards AND for PRTDs.
Now, they don't specify, but presumably if this form is submitted to get a PRTD while in Canada (and marked as 'in Canada'), it will either be rejected or treated as an application for a PR card (and possibly rejected if any relevant sections aren't completed).
The important part: since you sign by making a form of oath at the end ("I certify that all information ... is correct, complete, and accurate") you absolutely should NOT state that you are outside Canada (for example to save time by applying before you depart) if you are not - that is a misrepresetnation and grounds for .... Bad Stuff to happen to you and potentially your PR status.
I have not seen the online application form, but understand that it similarly a) compels the applicant to state their location, and b) swear a statement at the end that all of the information is true. I have heard that it is either more explicit about the 'you must be outside Canada to apply for PRTD' part, or even makes it impossible to apply for a PRTD without choosing the 'outside Canada' option (and also swearing to that effect).
So: IRCC may not physically
block you from applying for PRTD while in Canada - so it's technically 'possible', that doesn't mean it's
allowed or a good idea, because you may have to explicitly make a misrepresentation to do so.