npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

selectionchange-polyfill

v1.2.1

Published

A polyfill that fires `selectionchange` events for Firefox

Downloads

40

Readme

selectionchange-polyfill

A polyfill that fires selectionchange events for Firefox.

Why

Firefox has a select event for when the selection changes within an input or textarea element, but doesn't yet support the general selectionchange event like other major browsers (see feature request). This polyfill models its behavior after Google Chrome’s.

How to Use

Call selectionchange.start() to enable the polyfill and selectionchange.stop() to disable it. Both functions take an optional DOMDocument argument, defaulting to window.document.

Handlers for the selectionchange event should be registered on the document or its .defaultView (its window).

The event is not cancellable and carries no information about the previous or current selection.

<script src="selectionchange.js"></script>
<script>
selectionchange.start();

document.addEventListener('selectionchange', function (event) {
  var sel = this.getSelection();
  console.log('Selected text:', sel.rangeCount ? sel.getRangeAt(0).toString() : null);
});
</script>

Implementation Notes

This polyfill fires selectionchange immediately after most kinds of selection changes (identified with checkmarks below), but there are some unsupported edge cases.

Ways a user can create a new selection:

  • :white_check_mark: User presses primary mouse button
  • :white_check_mark: User double-clicks a word or triple-clicks a paragraph
  • :x: User chooses "Select All" from the context (right-click) menu 1
  • :x: User chooses "Select All" from the Edit menu in the menu bar 1
  • :white_check_mark: User types Ctrl+A (or Cmd+A) to select all
  • :white_check_mark: User tabs to a different focusable element

Ways a user can modify a selection:

  • :white_check_mark: User moves mouse while holding down primary mouse button
  • :white_check_mark: User holds down Shift key (and optionally Alt key) and clicks and/or drags mouse
  • :white_check_mark: User holds down Shift key (and optionally Alt key) and presses an arrow key
  • ~~User scrolls the wheel with the primary mouse button down~~ (a Chrome/Safari feature not in Firefox)

Ways a script can create or modify a selection:

  • :x: Using the Selection API 2
  • :x: Modifying the DOM within the selection, at a boundary, or with any overlap 2
  • :white_check_mark: Moving focus using .focus() or .blur()

If the document’s selection changes via an unsupported mechanism, the selectionchange event will not necessarily fire soon afterwards, but may still fire eventually, after a subsequent user action.

1 The reason this polyfill doesn’t currently support "Select All" menu item selection is that it doesn’t trigger a DOM event and is less common. Optional support via polling may be added in the future.

2 The reason this polyfill doesn’t currently support selection changes via script is that the author’s initial use case didn’t require it. Polling could be used to detect changes via the Selection API. A DOM MutationObserver could be used to detect selection changes resulting from DOM modifications.