Skip to content

Instantly share code, notes, and snippets.

@fronterior
Created April 13, 2022 12:37
Show Gist options
  • Save fronterior/e114fbcf26c1f5a902a534eadbd1dce4 to your computer and use it in GitHub Desktop.
Save fronterior/e114fbcf26c1f5a902a534eadbd1dce4 to your computer and use it in GitHub Desktop.
// https://stackoverflow.com/questions/836777/how-to-detect-browsers-protocol-handlers
// https://jsfiddle.net/stefansundin/0uca4h2o/
function checkRegisteredProtocol(protocol: string) {
const input = document.createElement('input');
input.style.position = 'absolute';
input.style.opacity = '0';
document.body.appendChild(input);
let isSupported = false;
input.focus();
input.onblur = () => isSupported = true;
location.href = `${protocol}://test.com`;
return new Promise(res => {
setTimeout(() => {
res(isSupported);
document.body.removeChild(input);
}, 300);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment