export function navigateToUrl(url) {
window.location.assign(url);
}
export function openExternal(url) {
const isTWA = document.referrer.startsWith('android-app://');
if (isTWA && /^https?:\/\//.test(url)) {
const urlObj = new URL(url);
const intentUrl = `intent://${urlObj.host}${urlObj.pathname}${urlObj.search}${urlObj.hash}#Intent;action=android.intent.action.VIEW;scheme=${urlObj.protocol.replace(':', '')};S.browser_fallback_url=${encodeURIComponent(url)};end;`;
window.__mobuxNavigateToUrl(intentUrl);
return;
}
const a = document.createElement('a');
a.href = url;
a.target = '_blank';
a.rel = 'noopener noreferrer';
a.style.display = 'none';
document.body.appendChild(a);
a.click();
a.remove();
}