AI • Science • Technology • Future

Side Projects

Feature-Detecting the Web Share API Before Showing a Share Button

Image from the original article
Featured image: original publisher image. Via original publisher.

A share button added to a tool page appeared to work on some devices but did nothing on others. The issue wasn’t code — it was a missing browser feature.

What Happened

The developer added a share button to their tool pages. It looked fine in the browser. But on half the devices tested, tapping it did nothing.

On some phones, the button was visible, but no action occurred. The page seemed complete — yet the one control users expect was dead. This kind of failure is particularly damaging because users often rely on such features to save or share content quickly, especially when using mobile devices.

Why the Button Failed

The problem was the Web Share API. The code used navigator.share() to open a native share sheet — like WhatsApp or Messages — which is designed to integrate seamlessly with a user’s existing apps.

But this API isn’t universal. Desktop Chrome supports it, mobile Safari does, but many browsers — including older versions of Android browsers and some mobile Safari variants — lack full support or only enable it under specific conditions. The developer assumed the API was available everywhere, which led to a poor user experience where users saw a button that did nothing.

How the Fix Works

The solution is simple and effective:

  • Check if navigator.share exists before showing the button.
  • If it does, show the button and attach a click handler.
  • If it doesn’t, hide the button entirely.

Here’s the key code:

const shareBtn = document.getElementById('share-btn');

if (navigator.share) {
  shareBtn.hidden = false;
  shareBtn.addEventListener('click', async () => {
    try {
      await navigator.share({
        title: document.title,
        text: 'Save this video with ramrom.io',
        url: window.location.href
      });
    } catch (err) {
      if (err.name !== 'AbortError') {
        console.warn('Share failed:', err);
      }
    }
  });
} else {
  shareBtn.hidden = true;
}

Two Key Details

First, the button starts hidden in the HTML. It doesn’t appear, then vanish. That flash makes users feel the page is broken. By hiding it from the start, the page avoids any moment of confusion or frustration.

Second, the code checks for AbortError. When a user opens the share sheet and closes it without selecting anything, the promise rejects with an AbortError. This is normal behaviour — not a failure. Logging it as an error would clutter the console and make it harder to identify actual issues that need fixing.

What About Browsers That Don’t Support It?

Visitors without the API lose nothing. They can still copy the link from the address bar. A copy-link button next to the share button works everywhere because it uses navigator.clipboard with a fallback. This ensures that even on unsupported devices, users can still save or share content, just through a different method.

The share button is a convenience — not a required feature. The page still functions with just a link and a download button. This design prioritizes reliability over feature bloat, which is essential for tools that serve diverse audiences.

Image from the original article
original publisher image. Via original publisher. · Source

Testing the Solution

The developer tested on real devices: an Android phone, an older iPhone, and desktop Chrome. These devices represent a range of browser capabilities and operating systems.

Emulators and feature tables show what *should* work. But only a real device shows what *does*. Testing on actual hardware reveals edge cases that software simulations miss — such as inconsistent rendering, outdated browser versions, or device-specific limitations.

Why This Matters

Feature detection is not just about one button. It’s a design principle.

Every browser feature added to the site now follows the same pattern: detect it, hide it if missing, and ensure the core experience remains intact. This approach makes the site feel responsive and reliable — not like a prototype with broken controls.

For developers building tools, this is a practical reminder: test on real devices. Detect features. Hide what doesn’t work. Keep the core experience solid.

The lesson is clear: a few lines of code can prevent a user from encountering a dead button. That difference is the difference between a working site and one that feels broken.

For more on browser tools that don’t upload your data, see Original source.

For more on browser tools that don’t upload your files, see Browser Tools That Never Upload Your Files.

Learn how AI prompts evolved through real tests in Three Real Halloween AI Video Tests.

And explore how to measure AI agent efficiency in How to Measure if AI Agents Actually Save Time.

Sources & further reading

Featured image: original publisher image. Via original publisher. Image source