在Chrome 86中检测自定义协议处理程序 [英] Detect Custom Protocol handler in chrome 86
问题描述
我已经根据
我发现如果我没有注册自定义协议,则chrome将打印因为该方案没有注册的处理程序".在控制台日志中,如下所示
如果(shell_integration :: GetApplicationNameForProtocol(url).empty()){web_contents-> GetMainFrame()-> AddMessageToConsole(眨眼:: mojom :: ConsoleMessageLevel :: kError,无法启动"+ url.possfully_invalid_spec()+"'因为该方案没有注册的处理程序.返回;}
但是如何从JavaScript代码中获取 shell_integration :: GetApplicationNameForProtocol(url).empty()
?
也请点击此处 https://support.google.com/chrome/thread/78279651?hl = zh_CN ,也没有答案.
I have implemented a solution according to https://gist.github.com/aaronk6/d801d750f14ac31845e8 and it worked fine till chrome 85 .With latest chrome Update Onblur not detecting open protocol handler popup. Is there a way to identify Custom protocol registered in windows using Chrome 86 new version .The code i have implemented mentioned below and it's working fine for Firefox
function LinkClicked() {
launchUri($(this).attr("href"), function () {
// SUCCESS APPLICATION INSTALLED
}, function () {
// PROTOCOL NOT REGISTERD IN REGISTRY
setTimeout(showAppInstallWarningMessage, 4000);
}, function () {
// STATUS CANNOT IDENTIFY
setTimeout(showAppInstallWarningMessage, 4000);
});
}
function launchUri(uri, successCallback, noHandlerCallback, unknownCallback) {
var res, parent, popup, iframe, timer, timeout, blurHandler, timeoutHandler, browser;
function callback(cb) {
if (typeof cb === 'function') cb();
}
function createHiddenIframe(parent) {
var iframe;
if (!parent) parent = document.body;
iframe = document.createElement('iframe');
iframe.style.display = 'none';
parent.appendChild(iframe);
return iframe;
}
function removeHiddenIframe(parent) {
if (!iframe) return;
if (!parent) parent = document.body;
parent.removeChild(iframe);
iframe = null;
}
browser = { isChrome: false, isFirefox: false, isIE: false };
if (window.chrome && !navigator.userAgent.match(/Opera|OPR\//)) {
browser.isChrome = true;
} else if (typeof InstallTrigger !== 'undefined') {
browser.isFirefox = true;
} else if ('ActiveXObject' in window) {
browser.isIE = true;
}
// EVALUATE msLaunchUri for IE 10+ browser in Windows 8+
if (navigator.msLaunchUri) {
navigator.msLaunchUri(uri, successCallback, noHandlerCallback);
}
// Evaluating Blur-hack Chrome and FireFox
else if (browser.isChrome || browser.isFirefox) {
blurHandler = function () {
window.clearTimeout(timeout);
window.removeEventListener('blur', blurHandler);
callback(successCallback);
};
timeoutHandler = function () {
window.removeEventListener('blur', blurHandler);
callback(noHandlerCallback);
};
window.addEventListener('blur', blurHandler);
timeout = window.setTimeout(timeoutHandler, 500);
window.location.href = uri;
}
else if (browser.isIE) {
popup = window.open('', 'launcher', 'width=0,height=0');
popup.location.href = uri;
try {
popup.location.href = 'about:blank';
callback(successCallback);
timer = window.setInterval(function () {
popup.close();
if (popup.closed) window.clearInterval(timer);
}, 500);
} catch (e) {
popup = window.open('about:blank', 'launcher');
popup.close();
callback(noHandlerCallback);
}
}
else {
iframe = createHiddenIframe();
iframe.contentWindow.location.href = uri;
window.setTimeout(function () {
removeHiddenIframe(parent);
callback(unknownCallback);
}, 500);
}
}
I tried both pagehide
and blur
but they both failed to work. I think it is because from chrome 86+ the external protocol handler does not blur the current page anymore.
Detecting Custom Protocol Handler in Windows 8+ with Chrome mentioned using HTML5 Visibility API I tried it too, but it also failed to work for Chrome 86+.
I feel we probably don't have a solution for Chrome 86+. The way vscode handles this can give us some hint. When you first visit https://marketplace.visualstudio.com/ no matter you have installed vscode or not it will pop this dialog.
And if you don't have vscode installed and you click open button in the external protocol handler, you won't get any error. This is a probably a sign that they can't get result of the external protocol handler either.
I find if I don't have custom protocol registered, chrome will print "because the scheme does not have a registered handler." in console log as here shows
if (shell_integration::GetApplicationNameForProtocol(url).empty()) {
web_contents->GetMainFrame()->AddMessageToConsole(
blink::mojom::ConsoleMessageLevel::kError,
"Failed to launch '" + url.possibly_invalid_spec() +
"' because the scheme does not have a registered handler.");
return;
}
But how can we get shell_integration::GetApplicationNameForProtocol(url).empty()
from javascript code?
Also check here https://support.google.com/chrome/thread/78279651?hl=en, no answer either.
这篇关于在Chrome 86中检测自定义协议处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!