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

devicechange-polyfill

v1.0.3

Published

Polyfill for navigator.mediaDevices.ondevicechange to detect Bluetooth headsets on Android Chrome.

Readme

devicechange-polyfill

npm version License: MIT

A polyfill for the navigator.mediaDevices.ondevicechange event that reliably detects changes to media devices (including Bluetooth and USB audio devices) on unsupported browsers—specifically on Android Chrome, Opera Android, Samsung Internet, and Android WebView.

Table of Contents

Features

  • Fallback for unsupported browsers: Applies only on browsers where the native devicechange event is not supported (Android Chrome, Opera Android, Samsung Internet, WebView).
  • Supports both approaches: Works with both the ondevicechange property and addEventListener('devicechange', callback).
  • Customizable polling: Change the polling interval dynamically using the provided API.
  • Lightweight and efficient: Automatically stops polling when there are no listeners.

Installation

Install via npm:

npm install devicechange-polyfill

Or using Yarn:

yarn add devicechange-polyfill

Usage

Simply import the polyfill at the start of your application. It will automatically detect if the browser requires the fallback behavior and patch navigator.mediaDevices accordingly.

Basic Usage

import 'devicechange-polyfill';

navigator.mediaDevices.ondevicechange = () => {
    // Handle media device changes here
    console.log('Media devices have changed!');
};

Using addEventListener

You can also use the event listener API:

import 'devicechange-polyfill';

navigator.mediaDevices.addEventListener('devicechange', () => {
    console.log('A media device was added or removed!');
});

Customizing Polling Interval

By default, the polyfill polls every 5000ms (5 seconds). You can change this interval using:

navigator.mediaDevices.setPollingInterval(2000); // Poll every 2 seconds

API

navigator.mediaDevices.ondevicechange

  • Type: function
  • Usage: Set a callback function that will be called when the polyfill detects a change in media devices.
  • Example:
    navigator.mediaDevices.ondevicechange = () => {
      console.log('Device change detected!');
    };

navigator.mediaDevices.addEventListener('devicechange', callback)

  • Usage: Add one or more event listeners for device changes.
  • Example:
    navigator.mediaDevices.addEventListener('devicechange', () => {
      console.log('A media device was added or removed!');
    });

navigator.mediaDevices.setPollingInterval(ms)

  • Parameters: ms — The polling interval in milliseconds (minimum recommended: 500ms).
  • Usage: Changes the interval at which the polyfill polls for device changes.
  • Example:
    navigator.mediaDevices.setPollingInterval(3000); // 3 seconds

Development

Building

This project uses Rollup to bundle the polyfill. To build the project:

npm run build

This will generate both a non-minified and minified version in the dist/ folder.

Running Tests

The tests use Jest and require a jsdom environment. Run the tests with:

npm test

A setup file (tests/setupTests.js) is used to mock the navigator.mediaDevices API for testing purposes.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines on how to contribute to this project.

License

This project is licensed under the MIT License.