QR Snapper is a simple, small, progressive web app that accesses the user's camera and looks for QR Codes.
The QR Code library is a port of JSQRCode and has been ported to work inside a Web Worker for performance.
QR Snapper offers a seamless QR code scanning experience directly in your browser. Key features include:
- Real-time QR Code Scanning: Instantly decode QR codes using your device's camera.
- Cross-Platform Compatibility: Tested and optimized for major browsers (Chrome, Firefox, Safari) and mobile devices.
- x-callback-url support: Allows other applications to receive the decoded QR code data.
To set up QR Snapper locally, follow these steps:
- Prerequisites:
- Node.js (v18 or later)
- npm (v9 or later)
- Installation:
- Clone the repository:
git clone https://github.com/PaulKinlan/qrcode.git - Navigate to the project directory:
cd qrcode - Install dependencies:
npm install
- Clone the repository:
- Development:
- Run the development server:
npm run dev - Open your browser to
http://localhost:8080
- Run the development server:
- Production Build:
- Build for production:
npm run build - Preview the production build:
npm run preview
- Build for production:
- Potential Issues:
- Ensure your Node.js and npm versions meet the prerequisites.
- Camera access may require browser permissions.
- Use HTTPS in production for camera and service worker support.
To quickly test QR Snapper, follow these steps:
-
Clone or Fork the Repository:
- *Note: This step requires an internet connection.*
- Clone the repository directly, or fork it and then clone your fork:
or
git clone [https://github.com/PaulKinlan/qrcode.git](https://github.com/PaulKinlan/qrcode.git)
git clone [https://github.com/YOUR_USERNAME/qrcode.git](https://github.com/YOUR_USERNAME/qrcode.git)
-
Navigate to the Project Directory:
- Open a terminal and navigate to the
qrcode/directory:cd qrcode
- Open a terminal and navigate to the
-
Install Dependencies:
- *Note: This step requires an internet connection.*
- Run
npm installto install the necessary dependencies (defined inpackage.json).
-
Open in Browser:
- Open
index.html(or your main HTML file) in your web browser.
- Open
Note: For full functionality (including camera access and advanced build processes), you may need to grant camera permissions and ensure your browser supports the necessary APIs. Refer to the full build instructions for details about build processes.
To better understand the codebase, here's a breakdown of the key components:
The application is now organized into focused, maintainable modules:
-
scripts/main.js:- Main entry point (32 lines) - initializes the application
- Much simpler than the previous 610-line monolithic file
-
scripts/components/:QRCodeCamera.js- Main application coordinatorcamera/CameraManager.js- Manages canvas rendering and camera displaycamera/CameraSource.js- Low-level camera API interface (modernized, no deprecated prefixes)camera/WebCamManager.js- Real-time webcam handling with camera switchingcamera/CameraFallbackManager.js- Image upload fallback when camera unavailabledialogs/QRCodeManager.js- Result dialog with share/copy/navigate actionsdialogs/QRCodeCallbackController.js- x-callback-url integrationdialogs/QRCodeHelpManager.js- About/help dialog
-
scripts/utils/:url-utils.js- URL normalization and security validation
-
scripts/qrclient.js:- Web Worker interface for QR code detection
- Uses Comlink for seamless worker communication
-
scripts/qrworker.js:- QR code detection worker implementation
- Uses native BarcodeDetector API when available
- Falls back to jsqrcode library polyfill
-
scripts/jsqrcode/:- JSQRCode library for QR detection
- Bundled from original source files
The application uses modern browser APIs:
- getUserMedia - No deprecated webkit/moz/ms prefixes
- BarcodeDetector API - Native QR detection when available
- Web Share API - Share detected URLs
- Clipboard API - Copy URLs to clipboard
- Service Workers - Offline support and caching
- The project uses Vite as the build tool (replaced Gulp)
- Modern ES modules throughout
- No Babel transpilation needed for modern browsers
- Optimized production builds with Rollup under the hood
We welcome contributions to QR Snapper! Please follow these guidelines:
- Reporting Issues:
- Use the GitHub issue tracker to report bugs or suggest feature requests.
- Development Setup:
- Fork the repository and create a branch for your changes.
- Coding Standards:
- Follow the existing code style and conventions.
- Pull Requests:
- Submit pull requests with clear descriptions of your changes.
- Ensure your code is tested and documented.
This project is licensed under the Apache License 2.0