Associate Files With Your PWA

Learn how to register your Progressive Web App as a file handler with the operating system for native-like file integration.

Understanding the File Handling API

The File Handling API extends Progressive Web Apps with the ability to register as file handlers at the operating system level. This represents a significant evolution in web capabilities--moving beyond the traditional model where web apps could only receive files through explicit upload mechanisms like file input elements or drag-and-drop zones.

With file handling enabled, your installed PWA can automatically launch when users open files of types you've registered. The operating system treats your PWA similarly to traditional desktop applications, passing the file directly to your app when the user double-clicks a file or selects your app from the "Open with" menu. This creates a seamless user experience where files and applications feel naturally connected.

How File Handling Works

The implementation involves two coordinated components working together. First, your web app manifest declares which file types your application can handle through the file_handlers array. This registration tells the operating system which file extensions and MIME types your app understands. Second, your JavaScript code uses the LaunchQueue API to receive and process files when your PWA is launched to handle them.

When a user opens a file associated with your PWA, the browser receives notification from the operating system and launches your application. The launch includes metadata about which files were opened, and your app can access these files through the LaunchParams interface. This handoff happens automatically--no file picker dialogs, no explicit user navigation required.

Why File Handling Matters for Cross-Platform Apps

For developers building cross-platform applications using React Native, iOS, and Android alongside web technologies, the File Handling API bridges an important gap between web and native experiences. Native mobile and desktop applications have long benefited from file association capabilities, allowing them to appear in sharing sheets and file open dialogs. Web applications historically lacked this integration, limiting their perceived value as true application alternatives.

Implementing file handling in your PWA signals to users that your application is a first-class citizen on their device. When your app appears alongside native software in file association dialogs, users recognize it as a capable, professional tool. This perception matters for adoption, retention, and user confidence in your application ecosystem. For teams working across multiple platforms, integrating these capabilities through our web development expertise ensures consistent file handling experiences regardless of how users access your application.

Declaring File Handlers in Your Manifest

The web app manifest serves as the declaration point for your PWA's file handling capabilities. Within the manifest file, you add a file_handlers array containing one or more handler definitions. Each handler specifies which file types it accepts and which URL within your application should receive file launch events.

Manifest Structure and Configuration

The file_handlers array contains objects with two essential properties. The accept property defines the file types your handler understands, structured as an object where keys are MIME types and values are arrays of corresponding file extensions. The action property specifies the URL path that should handle file launches--typically a dedicated route within your application designed to receive and process files.

This configuration tells the operating system exactly how to route files to your application. When a user opens a file, the system examines both the MIME type and file extension to match against registered handlers, then launches your PWA at the specified action URL with the file information available. Proper manifest configuration is essential for PWAs that need to integrate seamlessly with the desktop operating system, and our web development services can help you implement these capabilities correctly.

Example manifest.json with file_handlers
1{2 "name": "Video Player PWA",3 "short_name": "VideoPlayer",4 "start_url": "/",5 "display": "standalone",6 "icons": [7 {8 "src": "/icons/icon-192.png",9 "sizes": "192x192",10 "type": "image/png"11 },12 {13 "src": "/icons/icon-512.png",14 "sizes": "512x512",15 "type": "image/png"16 }17 ],18 "file_handlers": [19 {20 "action": "/open-video",21 "accept": {22 "video/mp4": [".mp4"],23 "video/webm": [".webm"],24 "video/quicktime": [".mov"]25 }26 },27 {28 "action": "/open-subtitle",29 "accept": {30 "text/vtt": [".vtt"],31 "text/plain": [".srt"]32 }33 }34 ]35}

MIME Types and File Extensions

Understanding the relationship between MIME types and file extensions is crucial for proper file handler configuration. MIME types (Multipurpose Internet Mail Extensions) are standardized identifiers for file formats, used across operating systems and applications to recognize file contents. File extensions are the text suffixes that typically appear at the end of filenames, helping users and systems identify file types visually.

When configuring accept, you can specify either MIME types, file extensions, or both. The system uses both pieces of information for matching--when a user opens a file, the operating system checks both the actual file type (via MIME type) and the filename extension. Including both provides robust matching across different operating systems and file naming conventions.

"accept": {
 "application/pdf": [".pdf"],
 "image/jpeg": [".jpg", ".jpeg"],
 "image/png": [".png"],
 "image/gif": [".gif"],
 "application/zip": [".zip"]
}

You can also use wildcard MIME types to match broader categories of files. For example, specifying "image/*" matches any image MIME type while still accepting the specified extensions. This approach provides flexibility for future image formats while maintaining the extensions you've defined. Understanding these nuances is critical for developers building PWAs that handle diverse file types across platforms.

Key File Handling Capabilities

The File Handling API provides essential capabilities for native-like file integration

Automatic File Launching

Your PWA launches automatically when users open registered file types through the file manager, providing immediate access to content.

Manifest Declaration

Simple JSON configuration in your web app manifest declares supported file types and handler URLs without complex setup.

LaunchQueue API

JavaScript API receives file handles when your PWA is launched to handle files through a clean consumer pattern.

Cross-Platform Support

Works across Windows, macOS, and Linux with Chromium-based browsers (Chrome 102+, Edge 102+) for broad desktop reach.

Implementing File Reception with LaunchQueue

Once your manifest declares file handlers, your JavaScript code must listen for and process incoming file launches. The LaunchQueue API provides this capability, allowing your application to register a consumer function that receives LaunchParams whenever your PWA is launched to handle files.

LaunchQueue API Basics

The LaunchQueue interface is available on the window object in supporting browsers. You access it through window.launchQueue and register a consumer using the setConsumer() method. This method accepts a callback function that will be invoked with LaunchParams containing information about the launched files.

The launchParams.files property contains an array of FileSystemHandle objects representing each file launched with your application. These handles provide access to the file's metadata and contents through the getFile() method, which returns a standard File object you can read using familiar File API methods.

LaunchQueue Implementation Example
1if ('launchQueue' in window) {2 launchQueue.setConsumer(async (launchParams) => {3 const files = launchParams.files;4 if (files && files.length > 0) {5 for (const fileHandle of files) {6 await processFile(fileHandle);7 }8 }9 });10}11 12async function processFile(fileHandle) {13 const file = await fileHandle.getFile();14 const fileName = file.name;15 const fileSize = file.size;16 const fileType = file.type;17 18 if (file.type.startsWith('video/')) {19 const objectURL = URL.createObjectURL(file);20 handleVideoFile(fileName, objectURL);21 } else if (file.type.startsWith('text/')) {22 const textContent = await file.text();23 handleTextFile(fileName, textContent);24 }25}

FileSystemHandle and File Types

The FileSystemHandle returned in launchParams.files is a base type with two specialized subtypes: FileSystemFileHandle for individual files and FileSystemDirectoryHandle for directories. For file handling scenarios, you'll work primarily with FileSystemFileHandle instances, which provide the getFile() method for accessing file contents.

The getFile() method returns a Promise that resolves to a File object containing the file's metadata (name, size, type, last modified date) and contents. This File object works with standard web APIs including FileReader, createImageBitmap for images, and URL.createObjectURL for creating blob URLs suitable for video and audio playback.

Processing Multiple Files

Users might launch your PWA with multiple files selected--for example, selecting several images for batch processing or multiple video files for a playlist. Your consumer function should handle this scenario gracefully, processing each file in sequence or in parallel as appropriate for your use case.

Progressive Enhancement Strategies

Since the File Handling API lacks universal support, implementing alternative file handling mechanisms ensures all users can work with files in your application, even if they cannot register as file handlers. Several web APIs provide complementary capabilities for handling files within an already-open application.

Web Share Target API

The Web Share Target API allows your PWA to register as a target for shares from other applications on the device. When a user selects your app in a sharing sheet, your application receives shared content including files. While designed primarily for sharing content between applications, this API provides file reception capabilities in scenarios where the File Handling API is unavailable.

File System Access API

The File System Access API provides complementary capabilities for reading and writing files that the user explicitly selects through file picker dialogs. While this API doesn't enable the automatic file launching that File Handling provides, it does allow deep integration with the local file system for applications that need to open, edit, and save files.

File Input and Drag-and-Drop

Traditional web approaches remain valid and widely supported. File input elements allow users to select files through system file dialogs, while drag-and-drop zones accept files dropped from file managers. These approaches work universally across all browsers and provide familiar interaction patterns for web users. Combining these approaches with the File Handling API creates comprehensive file handling experiences for PWAs.

Video & Media Players

Media player PWAs can launch automatically when users open video files, providing immediate playback without navigation steps.

Document Editors

Document editors and note-taking apps can register as handlers for their native file formats, positioning as legitimate productivity tools.

Graphics Tools

Image editors can appear alongside professional tools like Photoshop when users open image files, driving discovery and trial.

Best Practices and Implementation Guidelines

Permission and User Trust

The first time your PWA launches to handle a file, browsers display permission dialogs asking users to confirm they want your application to open files of that type. These dialogs protect users by ensuring explicit consent for file associations. Your application should be prepared to handle scenarios where users decline permission.

Design your file handling implementation with user control in mind. Provide clear instructions for setting or changing file associations through operating system interfaces. If users need to revoke file association permissions, ensure they can do so easily through your application's settings or documentation.

Error Handling and Edge Cases

File handling introduces several error scenarios your code must address. Users might launch your PWA with corrupted files, files in unsupported formats, or files your application cannot process for other reasons. Robust error handling provides meaningful feedback and maintains application stability.

Testing File Handling Implementation

Verifying file handling functionality requires testing with actual file operations rather than browser development tools alone. Create test files of each supported type and verify your application responds correctly when opening them through the file manager. Our web development team recommends comprehensive testing across all supported browsers and operating systems to ensure consistent file handling behavior.

Frequently Asked Questions

Ready to Build Your PWA?

Our team specializes in Progressive Web App development with native-like capabilities for cross-platform experiences. Contact us to discuss how file handling and other web APIs can enhance your application.

Sources

  1. MDN Web Docs: Associate files with your PWA - Core technical reference for file_handlers manifest member and LaunchQueue API
  2. Microsoft Learn: Handle files in a PWA - Implementation examples and demo app walkthrough
  3. Chrome Developers: File Handling API - Browser support matrix and progressive enhancement guidance