Re: [w3c/clipboard-apis] do we really need navigator.clipboard.platform? (#104)

[`navigator.clipboard.platform`](https://github.com/dway123/raw-clipboard-access/blob/master/explainer.md#navigatorclipboardplatform) is intended to be a simple and consistent way to detect the clipboard target that the user is currently on. This is because using `navigator.platform` + `navigator.userAgent` currently is fairly complex to use and sometimes inconsistent between browsers, as mentioned [here](https://stackoverflow.com/questions/19877924/what-is-the-list-of-possible-values-for-navigator-platform-as-of-today/19883965#19883965). Detecting a platform (OS) in a browser-independent way through `navigator.platform` + `navigator.userAgent` often requires complex regular expressions that would not be obvious to someone simply reading MDN or the spec. Using raw clipboard access with `navigator.clipboard.platform` could allow a web application to simply check the clipboard backing, which varies less than `navigator.platform` (ex. "x11 Linux" could be a consistent return value regardless of computer architecture (arm v. ppc v. intel, and 32-bit v. 64-bit)). Additionally, ChromeOS can sometimes be harder to detect, as it's sometimes labelled as Linux, and this would require only one API instead of 2 to detect the platform.

Here is some sample code showing how `navigator.clipboard.platform` may be a bit cleaner:
```javascript
// Through navigator.clipboard.platform, simple equality checks may be used.
if (navigator.clipboard.platform === 'Windows') {
  // Windows code.
} else if (navigator.clipboard.platform === 'MacOS') {
  // Mac code.
} else if(navigator.clipboard.platform === 'Android') {
  // Android code.
}
```
```javascript
// Through navigator.platform + navigator.userAgent, detection is slightly more complex
// source: https://stackoverflow.com/questions/38241480/detect-macos-ios-windows-android-and-linux-os-with-js
const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'];
const macOsPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'];

if (windowsPlatforms.indexOf(navigator.platform !== -1) {
  // Windows code.
} else if (macOsPlatforms.indexOf(navigator.platform) !== -1) {
  // Mac code.
} else if(/Android/.test(navigator.platform.userAgent)) {
  // Android code.
}
```

That said, `navigator.platform` already works and is well documented. There exist libraries like [platform.js](https://github.com/bestiejs/platform.js/issues) that make this easy to consume, and plenty of [content](https://stackoverflow.com/questions/38241480/detect-macos-ios-windows-android-and-linux-os-with-js) already describes how to detect a platform.

While this API may be more direct and simple to use for clipboard, it could certainly also be an unnecessary API that duplicates existing behavior, which increases maintenance costs and may add confusion. It also certainly isn't required to meet the [goals](https://github.com/dway123/raw-clipboard-access/blob/master/explainer.md#goals) for Raw Clipboard Access.

Summary:
I'm unsure that it's completely necessary, but there are pros and cons. This is still open for discussion, and I've filed an [issue](https://github.com/dway123/raw-clipboard-access/issues/5) asking for feedback/thoughts as well from TAG regarding this. 

Pros:
- simpler to detect clipboard backing platform
- more consistent to detect clipboard backing platform

Cons:
- extra API to maintain for browsers
- extra API for developers to disambiguate (looks odd)

(Thank you for asking this question, and sorry for the wall of text.)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/clipboard-apis/issues/104#issuecomment-541992972

Received on Tuesday, 15 October 2019 01:14:07 UTC