How to detect, from browser, if user is running in Remote Desktop session?
Asked Answered
S

6

14

Is there a ways to check inside a browser (e.g. javascript) if the user is running inside a Remote Desktop session?


If the user is running their browser inside a Remote Desktop (i.e. Terminal Services), i want to disable animations on the web-site.

If this were a native application, as opposed to a web-site, i could perform this checking using:

//Native code
isRemoteSession = GetSystemMetrics( SM_REMOTESESSION );

or

//Managed Code:
isRemoteSession = System.Windows.Forms.SystemInformation.TerminalServerSession;

Is there a similar check that can be done inside the browser?

Note: Assume for the purposes of this discussion that the browser we're talking about is Internet Explorer 8.


Update One: Perhaps something in How can you get the terminal service client machine name from javascript?

Shaunna answered 5/8, 2010 at 18:25 Comment(1)
+1 because it would be a great usability enhancement for many sites.Lavalava
F
6

You can use the following media query:

@media screen and (prefers-reduced-motion: reduce) { . . . }

This condition can also hold for non-RDP sessions, but as your intention is to disable all animations, this type of query is probably exactly what you're looking for.

Flavory answered 7/6, 2020 at 12:15 Comment(6)
Tested it and it works. Inside an RDP session, Chrome 83 uses reduce. It turns on reduce even if you turn on all visual experience effects, including Menu and window animation. Internet Explorer 11 and Edge don't set however.Shaunna
@IanBoyd Does this method still work? I tried to replicate the results without any luck.Whichever
@Whichever It does still work MDN example (Chrome 85, Edge 85)Shaunna
@IanBoyd May I ask what kind of RDP session did you test it on? I have tried TeamViewer and Windows RDP without luck.Whichever
@Whichever Browsed to the page while using RDP to connect to my work PC from home.Shaunna
I randomly stumbled upon this media query and the fact that Chrome uses it on RDP by seeing the React logo in their default app wasn't spinningExtremist
J
13

My solution is to use CSS @media queries for minimum and maximum values of the color media feature. Based on experiment, RDP only seems to have 5 bits per color, rather than the full 8 bits per color of your typical desktop.

This solution is, of course, not perfect, because you'll get lots of false positives from people who aren't on RDP, but just happen to have low color-depth displays. However:

  • If you are in a relatively controlled environment like a corporate intranet, you might feel more confident that "low color depth" = "RDP".
  • Many of the visual elements that need adjusting for RDP on a web-page, need adjusting precisely because of the low color depth (gradients, fade outs, animation, etc.), and so it actually makes sense to test for color depth rather than RDP per se.

Here is an example that works for me in recent version of Firefox and Chrome. See the screenshot below.

<!DOCTYPE html>
<html>
    <head>
        <title>Test RDP detection</title>
        <style type="text/css">
            @media all { li.color { display: none; } }
            @media all and (min-color: 1) { li.color.color-depth-1 { display: block; } }
            @media all and (min-color: 2) { li.color.color-depth-2 { display: block; } }
            @media all and (min-color: 3) { li.color.color-depth-3 { display: block; } }
            @media all and (min-color: 4) { li.color.color-depth-4 { display: block; } }
            @media all and (min-color: 5) { li.color.color-depth-5 { display: block; } }
            @media all and (min-color: 6) { li.color.color-depth-6 { display: block; } }
            @media all and (min-color: 7) { li.color.color-depth-7 { display: block; } }
            @media all and (min-color: 8) { li.color.color-depth-8 { display: block; } }

            /* 5 bits per color seems to be the max for RDP */
            @media all and (max-color: 5) {
                .not-rdp { display: none; }
            }
            @media all and (min-color: 6) {
                .rdp-only { display: none; }
            }
        </style>
    </head>
    <body>
        <p>This page uses CSS <tt>@media</tt> queries to detect whether you
            are viewing it over RDP&mdash;heuristically, by looking at the
            color depth of your display.</p>

        <ul>
            <li class="color color-depth-1">Your display is not monochrome!</li>
            <li class="color color-depth-2">Your display has at least 2 bits per color.</li>
            <li class="color color-depth-3">Your display has at least 3 bits per color.</li>
            <li class="color color-depth-4">Your display has at least 4 bits per color.</li>
            <li class="color color-depth-5">Your display has at least 5 bits per color.</li>
            <li class="color color-depth-6">Your display has at least 6 bits per color.</li>
            <li class="color color-depth-7">Your display has at least 7 bits per color.</li>
            <li class="color color-depth-8">Your display has at least 8 bits per color.</li>
        </ul>

        <p>You are <span class="not-rdp">not</span> using RDP.</p>
        <p class="rdp-only">This is only visible over RDP.</p>
    </body>
</html>

screenshot showing test page with and without RDP

Yet another approach along these lines is to use javascript to examine the value of the screen.colorDepth variable.

Joeannjoed answered 12/4, 2013 at 23:0 Comment(4)
Note that the color depth is configurable in the RDP client: see the Advanced/Display/Colors dropdown.Apocrypha
Just created a fiddle for this for people to test quickly: jsfiddle.net/7cqqpeqe - doesn't seem to work as a method any more though.Muzzleloader
This doesn't seem to work in Chrome but does work in Firefox at least. There's also a javascript function to test the colordepth: w3schools.com/jsref/…Stuckup
Was anyone successful in replicating those results?Whichever
F
6

You can use the following media query:

@media screen and (prefers-reduced-motion: reduce) { . . . }

This condition can also hold for non-RDP sessions, but as your intention is to disable all animations, this type of query is probably exactly what you're looking for.

Flavory answered 7/6, 2020 at 12:15 Comment(6)
Tested it and it works. Inside an RDP session, Chrome 83 uses reduce. It turns on reduce even if you turn on all visual experience effects, including Menu and window animation. Internet Explorer 11 and Edge don't set however.Shaunna
@IanBoyd Does this method still work? I tried to replicate the results without any luck.Whichever
@Whichever It does still work MDN example (Chrome 85, Edge 85)Shaunna
@IanBoyd May I ask what kind of RDP session did you test it on? I have tried TeamViewer and Windows RDP without luck.Whichever
@Whichever Browsed to the page while using RDP to connect to my work PC from home.Shaunna
I randomly stumbled upon this media query and the fact that Chrome uses it on RDP by seeing the React logo in their default app wasn't spinningExtremist
F
1

You can probably expose the detection code via an ActiveX or BHO (e.g. assign a property to the window object in BHO) if you use IE.

Otherwise if you are using an ActiveX player to play animation, check the player's documentation to see if it automatically adjust frame rate under remote desktop.

You can always offer a low bandwidth version of your web site and instruct the user choose the web site instead of the regular web site if the video playback is not satisfactory.

For tips in writing a terminal service-aware graphics app, check graphic effects consideration, and the general performance guidelines

Fraktur answered 3/9, 2011 at 19:25 Comment(2)
"Let the user choose a low bandwidth version" is the correct answer.Apocrypha
Ben, not really as that still requires loading the page once before you can choose. Also, the needed bandwidth isn't really the problem over RDP, it's animations, large images, etc. since those make navigating a site nigh-unusable via RDP (since the display updates interfere with interaction).Larghetto
U
0

Perhaps you can read the SESSIONNAME environment variable? For a console session it should be CONSOLE and for an RDP session it should be RDP-TCP followed by a number.

Unders answered 2/10, 2010 at 15:16 Comment(1)
Reading environment variables with client Javascript in the browser? I doubt it.Larghetto
B
0

I'm assuming you are talking about a specific company terminal server, not any terminal server. You could not serve animations to the specific IP address of the TS.

Bassesalpes answered 28/11, 2010 at 12:18 Comment(1)
No, any terminal server. If you RDP to your home machine from at work, and go browsing my web-page: animations should not play.Shaunna
K
-2

This should not be done or decided by your application. On RDP client (like MS RDC), user can choose to disable animations etc. User can also disable these on server side (Terminal server or RDP host)

Kiri answered 25/2, 2014 at 22:13 Comment(1)
The RDP connection performance options (such as animations, wallpapers, etc) are not exposed to in-browser applications, and browsers will render CSS/JavaScript animations regardless of RDP settings. Until there is an API exposed to see if animations and other features should be disabled in a web-application all we can do are little tricks to detect the environment.Disproportionate

© 2022 - 2024 — McMap. All rights reserved.