TEXT: navigator.share({title: '...', text: '...'}) URL: Share URL to native apps FILES: Share images and documents
Use the controls on the left to test different sharing scenarios
// 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' });
View, manage, and export browser localStorage data with comp...
Upload SQL schema and generate Entity-Relationship Diagrams ...
Test your webcam, microphone, and WebRTC connections instant...
Explore WebAssembly capabilities with performance comparison...
Master essential privacy and security tools for 2025. From password generation and breach monitoring...
Supercharge your development workflow with professional code optimization, testing, and debugging to...
Master professional typography with comprehensive font selection, pairing, and implementation tools....
Master file management and document processing with professional PDF, OCR, and conversion tools. Str...
Professional code debugging and development solutions for developers.