Web Share API Demo

Comprehensive demonstration of the Web Share API for developers. Test sharing text content, URLs, images, and files using the native sharing capabilities of modern browsers and devices. Includes feature detection, fallback mechanisms, and practical examples for implementation.
Native Sharing Feature Detection Fallback Options File Sharing
Quick Examples
TEXT: navigator.share({title: '...', text: '...'})
URL: Share URL to native apps
FILES: Share images and documents
API Support
Web Share API: Checking...
File Sharing: Checking...
Browser: Detecting...
Platform: Detecting...
Text Sharing
File Sharing
Select images, documents, or text files to share
Quick Examples
Live Demo Results
Ready to Share!

Use the controls on the left to test different sharing scenarios

Implementation Code
// Basic Web Share API implementation
async function shareContent() {
    // Check if Web Share API is supported
    if (!navigator.share) {
        console.log('Web Share API not supported');
        showFallbackOptions();
        return;
    }

    const shareData = {
        title: 'My Awesome App',
        text: 'Check out this amazing content!',
        url: 'https://example.com'
    };

    try {
        await navigator.share(shareData);
        console.log('Content shared successfully');
    } catch (error) {
        if (error.name === 'AbortError') {
            console.log('Share was cancelled by user');
        } else {
            console.error('Error sharing:', error);
        }
    }
}
// File sharing with Web Share API
async function shareFiles(files) {
    // Check if file sharing is supported
    if (!navigator.canShare || !navigator.canShare({ files: files })) {
        console.log('File sharing not supported');
        return;
    }

    const shareData = {
        title: 'Shared Files',
        text: `Sharing ${files.length} file(s)`,
        files: files
    };

    try {
        await navigator.share(shareData);
        console.log('Files shared successfully');
    } catch (error) {
        console.error('Error sharing files:', error);
    }
}

// Example usage with file input
const fileInput = document.getElementById('fileInput');
const files = Array.from(fileInput.files);

if (files.length > 0) {
    shareFiles(files);
}
// Complete Web Share API implementation with fallbacks
class WebShareManager {
    constructor() {
        this.isSupported = 'share' in navigator;
        this.canShareFiles = this.isSupported && 'canShare' in navigator;
    }

    async share(shareData) {
        if (!this.isSupported) {
            this.showFallback(shareData);
            return false;
        }

        // Validate file sharing if files are present
        if (shareData.files && !this.canShareFiles) {
            console.warn('File sharing not supported');
            delete shareData.files;
        }

        try {
            await navigator.share(shareData);
            return true;
        } catch (error) {
            this.handleShareError(error);
            return false;
        }
    }

    handleShareError(error) {
        switch (error.name) {
            case 'AbortError':
                console.log('Share cancelled');
                break;
            case 'NotAllowedError':
                console.log('Share not allowed');
                break;
            case 'TypeError':
                console.log('Invalid share data');
                break;
            default:
                console.error('Share error:', error);
        }
    }

    showFallback(shareData) {
        // Implement fallback sharing options
        if (shareData.url) {
            this.copyToClipboard(shareData.url);
        } else if (shareData.text) {
            this.copyToClipboard(shareData.text);
        }
    }

    async copyToClipboard(text) {
        try {
            await navigator.clipboard.writeText(text);
            console.log('Copied to clipboard');
        } catch (err) {
            console.error('Copy failed:', err);
        }
    }
}

// Usage example
const shareManager = new WebShareManager();
shareManager.share({
    title: 'My App',
    text: 'Amazing content to share!',
    url: 'https://example.com'
});
Feature Detection
--
Text Sharing
--
File Sharing
User Agent:
Loading...
Share History
No shares yet. Start sharing to see history!

Help & Related Tools

Everything you need to know

FAQ Frequently Asked Questions

What sharing capabilities does this demo showcase?
This demo showcases text sharing, URL sharing, file sharing, contact card sharing, and image generation with sharing. It includes feature detection and fallback mechanisms for unsupported browsers.
How do I test the Web Share API features?
Use the controls on the left to test different sharing scenarios. Try sharing text content, selecting files to share, or use the quick examples. The demo will show real-time results and implementation code.
Which browsers support the Web Share API?
The Web Share API is supported in Chrome, Safari, and Edge on mobile devices and some desktop platforms. Firefox currently does not support it. The demo includes automatic feature detection and fallback options.
What are the limitations of the Web Share API?
The API requires user activation (button click), works only on HTTPS, and file sharing support varies by browser and platform. Some browsers limit file types and sizes that can be shared.
Can I use this code in my own applications?
Absolutely! The demo provides ready-to-use implementation code with proper feature detection and error handling. Copy the code examples and adapt them for your specific use cases.

TOOLS Similar in Developer

LocalStorage Viewer

View, manage, and export browser localStorage data with comp...

SQL Schema to ERD Visualizer

Upload SQL schema and generate Entity-Relationship Diagrams ...

WebRTC Tester

Test your webcam, microphone, and WebRTC connections instant...

WebAssembly Demo

Explore WebAssembly capabilities with performance comparison...

Something not working? Idea for a great tool? Contact our team or browse all tools

Explore More Resources

Latest Articles

Cybersecurity
Privacy & Security Toolkit: Password Management & Data Protection Tools

Master essential privacy and security tools for 2025. From password generation and breach monitoring...

Jun 9, 2025 90
Web Development
Essential Developer Productivity Tools: Code Generation & Testing Suite

Supercharge your development workflow with professional code optimization, testing, and debugging to...

Jun 9, 2025 144
Typography
Typography & Font Management: Creating Beautiful Text Experiences

Master professional typography with comprehensive font selection, pairing, and implementation tools....

Jun 10, 2025 135
Document processing
File Management & Document Processing: PDF, OCR & Conversion Tools

Master file management and document processing with professional PDF, OCR, and conversion tools. Str...

Jun 9, 2025 114

Developer Resources

BugFixCode.com

Professional code debugging and development solutions for developers.

  • Code Review & Debugging
  • Performance Optimization
  • Best Practices Guide
  • Developer Tools
Trusted by developers worldwide