Fix browser phone init not starting on mobile (window.load not firing)
All checks were successful
Create Release / build (push) Successful in 3s
All checks were successful
Create Release / build (push) Successful in 3s
The window.load event was never firing on mobile tablets, preventing the browser phone from initializing. Changed to poll for Twilio SDK availability instead of waiting for window.load event. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8253,20 +8253,40 @@ class TWP_Admin {
|
|||||||
|
|
||||||
// Check if SDK loaded and initialize
|
// Check if SDK loaded and initialize
|
||||||
debugLog('jQuery ready');
|
debugLog('jQuery ready');
|
||||||
$(window).on('load', function() {
|
|
||||||
debugLog('Window loaded');
|
// Don't wait for window.load - it may not fire on mobile
|
||||||
setTimeout(function() {
|
// Instead, poll for Twilio SDK availability
|
||||||
debugLog('Checking Twilio: ' + (typeof Twilio));
|
var sdkCheckAttempts = 0;
|
||||||
if (typeof Twilio === 'undefined') {
|
var maxSdkCheckAttempts = 50; // 5 seconds max
|
||||||
showError('Twilio Voice SDK failed to load. Please check your internet connection and try refreshing the page.');
|
|
||||||
console.error('Twilio SDK not found. Script may be blocked or failed to load.');
|
function checkAndInitialize() {
|
||||||
debugLog('SDK FAILED');
|
sdkCheckAttempts++;
|
||||||
} else {
|
debugLog('SDK check #' + sdkCheckAttempts + ': ' + (typeof Twilio));
|
||||||
|
|
||||||
|
if (typeof Twilio !== 'undefined' && Twilio.Device) {
|
||||||
console.log('Twilio SDK loaded successfully');
|
console.log('Twilio SDK loaded successfully');
|
||||||
debugLog('SDK OK, initializing...');
|
debugLog('SDK OK, initializing...');
|
||||||
initializeBrowserPhone();
|
initializeBrowserPhone();
|
||||||
|
} else if (sdkCheckAttempts < maxSdkCheckAttempts) {
|
||||||
|
// Keep checking every 100ms
|
||||||
|
setTimeout(checkAndInitialize, 100);
|
||||||
|
} else {
|
||||||
|
showError('Twilio Voice SDK failed to load. Please check your internet connection and try refreshing the page.');
|
||||||
|
console.error('Twilio SDK not found after ' + sdkCheckAttempts + ' attempts.');
|
||||||
|
debugLog('SDK FAILED after ' + sdkCheckAttempts + ' attempts');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start checking after a brief delay
|
||||||
|
setTimeout(checkAndInitialize, 500);
|
||||||
|
|
||||||
|
// Also keep the window.load as backup for desktop
|
||||||
|
$(window).on('load', function() {
|
||||||
|
debugLog('Window loaded (backup)');
|
||||||
|
if (typeof Twilio !== 'undefined' && !device) {
|
||||||
|
debugLog('Backup init triggered');
|
||||||
|
initializeBrowserPhone();
|
||||||
}
|
}
|
||||||
}, 1000);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Clean up on page unload
|
// Clean up on page unload
|
||||||
|
|||||||
Reference in New Issue
Block a user