Build an Advanced Surface Tracking Experience
Advanced UX Control and Customization for Experienced Developers
Introduction
This guide walks you through building an advanced surface tracking experience using the WebAR SDK with custom progress handlers, error management, and enhanced user experience. This builds upon the basic surface tracking guide by adding professional-grade features for production applications. Why Build an Advanced Experience?
Professional UX: Custom loading screens with real-time progress indicators and comprehensive error handling provide a polished, branded user experience that builds trust and engagement.
Real-time Monitoring: Track actual SDK loading progress with precise percentage and object count data instead of generic spinners, giving users meaningful feedback about loading status.
Full Control on Camera Stream: Manage camera permissions, initialization, and error handling manually with
external-camera-stream="true", enabling custom permission prompts and better user guidance for camera-related issues.Headless Mode: With
minimal-ui="true"+on-progress+on-error, the screen goes completely white (no default SDK UI), then opens the camera and starts the AR pipeline - giving you complete control to implement your own UI and user flow.
Prerequisites
Complete the basic surface tracking experience first, or have familiarity with basic WebAR SDK integration.
Understanding Custom Handlers
on-progress Attribute
on-progress AttributeThe on-progress attribute allows you to receive real-time loading progress data from the WebAR SDK:
// Your custom progress handler receives this data:
function customProgressHandler(progress) {
// progress.percentage - Loading completion (0-100)
// progress.current - Current loaded objects
// progress.total - Total objects to load
}Pass this function to on-progress attribute while loading WebAR SDK script:
Why use on-progress?
Replaces generic "Loading..." with actual progress percentages
Shows users detailed loading status (e.g., "Loading AR engine: 75%")
Debugs loading performance issues
Provides smooth, professional loading experience
on-error Attribute
on-error AttributeThe on-error attribute provides comprehensive error information when something goes wrong:
Error Codes You May Receive:
Why use on-error?
Shows user-friendly error messages instead of browser console errors
Provides specific instructions for different error types
Tracks and debug issues in production
Handles camera, sensor, and browser compatibility problems gracefully
minimal-ui Attribute
minimal-ui Attribute Set minimal-ui="true" to disable the SDK's default UI and enable your custom handlers.
Why minimal-ui="true" is required:
Disables SDK's built-in loading screen and error dialogs
Allows your custom progress and error handlers to take full control
Prevents conflicts between default UI and your custom UI
Essential for professional, branded experiences
Process
Step 1: Project Structure Setup
Why this structure? Separating concerns makes your code maintainable and reusable across projects.
Step 2: Create Custom Handler Functions
Why create this first? The SDK needs these functions available before it loads, so we define them early. Create custom-handlers.js:
Step 3: Enhanced HTML with Advanced Configuration
Why load handlers before SDK? The SDK looks for callback functions immediately when it loads.
Critical Configuration Explained:
minimal-ui="true" - REQUIRED for custom UX
What it does: Disables SDK's default loading screen and error dialogs
Why required: Allows your custom handlers to control the entire user experience
Without it: Your custom progress/error handlers won't be used
on-progress="customProgressCallback"
What it does: Tells SDK to call your customProgressCallback function with loading data
Why useful: Get real-time loading progress instead of generic spinners
Data received: percentage, current objects loaded, total objects
on-error="customErrorCallback"
What it does: Tells SDK to call your customErrorCallback function when errors occur
Why essential: Handle camera permissions, browser compatibility, and other issues gracefully
Data received: error code, description, user instructions, browser info
external-camera-stream="true"
What it does: Lets you manage camera permissions and stream manually
Why important: Better user experience with custom permission prompts
Enables: iOS permission handling, custom camera error messages
Step 4: Enhanced Loading Screen / Custom Splash Screen
Why custom loading screen? Professional apps need branded, informative loading experiences.
With minimal-ui="true", the SDK provides no default UI - you must create your own splash screen and manage its lifecycle. Please note that you may use the on-load attribute to override the default SDK splash screen while keeping other SDK UI elements when minimal-ui="false" .
Critical Timing: Load Splash Screen Before SDK loads
Important: Load your custom-handlers.js script BEFORE the WebAR SDK script. With minimal-ui="true", the SDK provides no default UI, so without your custom handlers loaded first, users will see a blank white screen during SDK initialization. Your custom handlers automatically create and inject the splash screen when the SDK starts loading.
Why this order matters:
minimal-ui="true"disables all SDK UISDK immediately calls
customProgressCallbackwhen loading startsIf your handlers aren't loaded yet → white screen
With handlers loaded first → instant professional splash screen
Your custom-handlers.js contains all the splash screen creation logic, so no additional HTML or CSS setup is required in your main page.
Step 5: Camera and Sensor Management
Why manual camera management? Better control over permissions and error handling.
Step 6: Complete WebAR Scene
Advanced Features Explained
Real-time Progress Monitoring
The customProgressHandler receives actual SDK loading data including:
progress.percentage- Loading completion (0-100)progress.current- Current loaded objectsprogress.total- Total objects to load
External Camera Stream
Using external-camera-stream="true" gives you full control over camera initialization, allowing for custom permission handling and better user experience.
Comprehensive Error Handling
The error handler provides detailed error information and user-friendly messages for different error scenarios.
Deployment Considerations
HTTPS Required: WebAR requires HTTPS for camera access
License Key: Replace YOUR_LICENSE_KEY_HERE with your actual license key
Asset Optimization: Optimize 3D models for web delivery
Browser Testing: Test across Safari (iOS) and Chrome (Android)
Full Source Code
The complete implementation is available in the WebAR SDK repository under /aframe/advanced-surface-tracking/.
Common Issues and Solutions
Progress handler not called?
Ensure minimal-ui="true" is set
Check that custom-handlers.js loads before the SDK
Verify function names match exactly
Error handler not working?
Confirm
on-errorattribute points to correct function nameCheck browser console for JavaScript errors
Ensure error UI elements exist in DOM
Camera permissions failing?
Verify HTTPS is enabled
Test iOS/Android permission prompt timing
Check camera constraints are supported
Key Benefits of This Advanced Implementation
Your advanced surface tracking experience will include:
Professional loading screen with real-time progress
Comprehensive error handling and user guidance
Smooth camera and sensor permission management
Enhanced debugging capabilities for development
Modular code architecture for easy maintenance
This advanced implementation provides a professional, production-ready foundation for WebAR applications with comprehensive UX control and error handling.
Last updated