()
| 282 | * and open them via the opener plugin instead of the webview. |
| 283 | */ |
| 284 | export const initExternalLinkHandler = (): void => { |
| 285 | if (!isTauri()) return; |
| 286 | document.addEventListener('click', (e) => { |
| 287 | if (e.defaultPrevented) return; |
| 288 | const a = (e.target as Element | null)?.closest?.('a[href]') as HTMLAnchorElement | null; |
| 289 | if (!a) return; |
| 290 | const href = a.getAttribute('href') || ''; |
| 291 | if (!/^(https?:|mailto:|tel:|sms:)/i.test(href)) return; |
| 292 | // Same-origin http(s) links are in-app navigation |
| 293 | if (/^https?:/i.test(href) && new URL(href).origin === window.location.origin) return; |
| 294 | e.preventDefault(); |
| 295 | void openExternal(href); |
| 296 | }); |
| 297 | }; |
no test coverage detected