SharedDirectoryAnnounce#960
Conversation
|
Is there a cluster I could connect to to try this out? |
ravicious
left a comment
There was a problem hiding this comment.
A preemptive approval with two caveats:
- I didn't have a chance to actually test this.
- I don't know what our requirements are when it comes to browser support for desktop access. If we run some checks before the execution gets to
window.showDirectoryPicker()then it's fine. But if not then we should add some feature checks.
| const sharedDirHandle = window | ||
| .showDirectoryPicker() |
There was a problem hiding this comment.
Do we need to handle browsers which don't support this API?
| const cfg = { | ||
| // TODO(isaiah): remove after feature is finished. | ||
| enableDirectorySharing: false, // note to reviewers: should be false in any PRs. | ||
| enableDirectorySharing: true, // note to reviewers: should be false in any PRs. |
There was a problem hiding this comment.
This feels like one of those logic puzzles… 🤔
But in all seriousness, is it supposed to be true or false in the end? 😅
There was a problem hiding this comment.
Haha
You got it correct, its supposed to be false in the end. Fixed.
| isSharingDirectory={isSharingDirectory} | ||
| onShareDirectory={() => { | ||
| setIsSharingDirectory(true); | ||
| window |
There was a problem hiding this comment.
Should probably add a check for the existence of window.showDirectoryPicker so that this doesn't throw on unsupported browsers.
And as a little nitpick, I don't like defining functions within the render portion of a component as it bloats the markup and makes it harder to follow.
There was a problem hiding this comment.
Should probably add a check for the existence of window.showDirectoryPicker so that this doesn't throw on unsupported browsers.
I left that as a "known issue" for now: #959, since we will want to add some error handling and UI message, but I am just focusing on getting the core functionality working.
There was a problem hiding this comment.
I read #959 as actually implementing the handling functionality, not protecting against the application throwing in browsers that don't support it.
There was a problem hiding this comment.
Basically I'm trying to charge forward with the core implementation in browsers that actually support it, and then go back at the end and write the code that makes sure the UX isn't totally confusing in browsers that don't.
There was a problem hiding this comment.
FWIW, I tried it with Firefox and I wasn't able to get to the point where the UI would allow me to trigger this code. The Web UI blocked me from using remote desktops and showed this message:
Your user role supports clipboard sharing over desktop access, however this feature is only available on chromium based browsers like Brave or Google Chrome. Please switch to a supported browser.
It didn't start the session so there was no risk of this code crashing.
kimlisa
left a comment
There was a problem hiding this comment.
We will also occasionally get a Uncaught (in promise) DOMException: Document is not focused. error when this permission modal pops up, or maybe more accurately, once sharedDirHandle is initialized
not sure what the error is without manually testing it but did you try focusing before calling the func?
Not that I know of. @zmb3 is there something we can spin up or that you can hand off? |
No I hadn't tried that. I just tried const onShareDirectory = () => {
window.focus();
...
};and const onShareDirectory = () => {
document.getElementById('app').focus();
...
};to no avail |
|
Re: "Document is not focused" error, it's interesting that it's reported as This code doesn't seem to be what's triggering it as the event handler function itself isn't executed within a promise. The promise returned by webapps/packages/teleport/src/DesktopSession/DesktopSession.tsx Lines 161 to 172 in bc6586b Matter of fact, when I changed the event handler to this: onShareDirectory={() =>
Promise.resolve()
.then(() => window.showDirectoryPicker())
.then(sharedDirHandle => {
setIsSharingDirectory(true);
tdpClient.sharedDirectory = sharedDirHandle;
tdpClient.sendSharedDirectoryAnnounce();
})
.catch(e => {
console.log('onShareDirectory error', { e });
setIsSharingDirectory(false);
})
}the error was still reported as "Uncaught (in promise)". 🤔 |
|
Yeah I was messing around and noticed the same thing (I tried wrapping that entire section in a try catch). The behavior is also inconsistent, for example I tried just now and wasn't able to induce the error. Seems like a bug in the implementation somewhere. |
UX
Allows the user to select "Share Directory" from the dropdown

And choose a directory to share

If necessary, the user will be prompted to allow access to the directory
At this point, the session will terminate because we will receive an unimplemented TDP message.
Notes
Couldn't find a permission name
Unfortunately, unlike the clipboard feature, I wasn't able to find a permission name to query for this permission preemptively
webapps/packages/teleport/src/DesktopSession/useClipboard.ts
Line 61 in bc6586b
The list of permission names for Chrome is linked by MDN's documentation to here, but none of these are what we are looking for.
Mysterious DOMException
We will also occasionally get a
Uncaught (in promise) DOMException: Document is not focused.error when this permission modal pops up, or maybe more accurately, oncesharedDirHandleis initialized:webapps/packages/teleport/src/DesktopSession/DesktopSession.tsx
Lines 162 to 171 in bc6586b
It's not entirely clear to me why this happens -- I've struggled to find a way to reproduce it consistently, though denying the permission in the modal and then asking for it again tends to work most of the time. There is limited information on Google about it. Most of the information relates to the clipboard API, which we dealt with here by checking for focus:
webapps/packages/teleport/src/DesktopSession/useTdpClientCanvas.tsx
Lines 150 to 159 in bc6586b
However even if I try adding such a check like so
I still encounter the error. The odd thing is, without the check, everything still seems to run according to plan, even if the error occurs. With the check, the error occurs but then
tdpClient.sendSharedDirectoryAnnounce();never gets called.As far as I can tell, the worst thing that will happen by letting this error slide is that the console will have some uncaught exceptions. It could just be a function of this being a bleeding edge feature.
Other known issues
Opportunistically
Also removes the recording symbol, closes gravitational/teleport#13973
How to test manually
teleportBuild and run the
windows-desktop-directory-sharingbranch, editing this line in the Makefile to have thedirectory_sharingbuild flag:webappsChange the value below to
trueand run the dev serverwebapps/packages/teleport/src/config.ts
Line 32 in becfad3
Requires backport to v9/v10