1

I'm thinking about using the following property (isCollapsed) from the Selecion API in my client code. For example, how can I know since which Firefox version this is supported?

const selection = window.getSelection();
selection.isCollapsed; // I want to know if all my target browsers have this implemented

On MDN, I got this: "Yes" (see picture with table below - last row of the table):

https://developer.mozilla.org/en-US/docs/Web/API/Selection

The compatibility table says "Yes" for Firefox, but I got also from their GitHub Repo that:

version_added This is the only mandatory property and it contains a string with the version number indicating when a sub-feature has been added (and is therefore supported). The Boolean values indicate that a sub-feature is supported (true, with the additional meaning that it is unknown in which version support was added) or not supported (false). A value of null indicates that support information is entirely unknown.

enter image description here

On the Can I Use website, I couldn't get all the properties and methods. Just the top-level API.

QUESTION

So, right now I know isCollapsed it's supported by Firefox, but don't know since which version. What should I do? Is there anyway to find out without reading all versions releases since V1?

enter image description here

cbdeveloper
  • 27,898
  • 37
  • 155
  • 336
  • 1
    Short answer, yes, but you will go crazy down that path. Instead, drop the way you think and instead start using progressive enhancement. That simply means, code the base of your web site for the lowest/oldest version you need to support, and then, using feature-detection, enhance the one's that have a given feature supported. For the browsers below what you will support, show them a message to upgrade. – Asons Apr 23 '19 at 16:16
  • Here's an answer of mine, that could be a reasonable starting point as of today: [I want to ask site visitors to upgrade their browser](https://stackoverflow.com/a/34812442/2827823) ...and have also a look at the 2nd most voted answer as well, it has some nice scripts – Asons Apr 23 '19 at 16:19
  • Thanks. I'm working on a personal project. How would you approach on which browsers to support? If I look into a browser's usage statistics by version and leave out anything below 0.5%, is this a good choice if I intend to target a general public? Is there like a good rule of thumb or starting point? – cbdeveloper Apr 23 '19 at 16:24
  • I decided for myself to use Flexbox as my base tech, and today it has a global support at 98.59%, which I found more than good enough. That means that I support up to 4-5 years old browser, and as my code base could be cut in less than half with it, a no brainer decision.. – Asons Apr 23 '19 at 16:31
  • Thanks again. Just as an example: would you use something like this: [Array.prototype.includes](https://caniuse.com/#feat=array-includes) ? Or would you look for a simpler solution that wouldn't require this feature? I know it's a personal decision. I'm just trying to understand how to reason about this kind of decision. Something like: "if the project has a target browser's list, it's done, end of story", but if you're free to chose, how to weight the pros and cons of a specific feature? Like enough support (~95%) and it saves code lines is a good way to think? – cbdeveloper Apr 23 '19 at 16:44
  • CSS is the tech that I decided to base my coding on, since it reduce markup (and with that performance). Script doesn't in the same way, so whether to use _Array.prototype.includes_ in favor of _Array.prototype.indexOf_ doesn't matter, and since in this case IE11 support Flexbox and not _Array.prototype.includes_, I go with _indexOf_. So that is my logic. – Asons Apr 23 '19 at 18:23

1 Answers1

0

Usually when the compatibility tables say (Yes) you likely don't have to worry about compatibility, unless you know you have to support a certain old version of some browser.

The only way to know for sure is testing with the versions of the browser you care about.

For selection.isCollapsed in particular my guess is that it's supported since before Firefox 1.0, as it was used in the Firefox UI back then.

Nickolay
  • 31,095
  • 13
  • 107
  • 185