Javascript 检测chrome 86中的自定义协议处理程序
我已经根据实现了一个解决方案,它在chrome 85之前运行良好。最新的chrome更新Onblur没有检测到开放协议处理程序弹出窗口。有没有一种方法可以识别使用Chrome86新版本在windows中注册的自定义协议Javascript 检测chrome 86中的自定义协议处理程序,javascript,google-chrome,chromium,google-chrome-app,custom-protocol,Javascript,Google Chrome,Chromium,Google Chrome App,Custom Protocol,我已经根据实现了一个解决方案,它在chrome 85之前运行良好。最新的chrome更新Onblur没有检测到开放协议处理程序弹出窗口。有没有一种方法可以识别使用Chrome86新版本在windows中注册的自定义协议 function LinkClicked() { launchUri($(this).attr("href"), function () { // SUCCESS APPLICATION INSTALLED
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);
}
}
我尝试了
pagehide
和blur
,但都失败了。我认为这是因为Chrome86+的外部协议处理程序不再模糊当前页面
提到使用,我也尝试过,但在Chrome86+上也失败了
我觉得我们可能没有Chrome86+的解决方案。vscode处理这一问题的方式可以给我们一些提示。当您第一次访问时,无论您是否安装了vscode,它都会弹出此对话框
如果您没有安装vscode,并且在外部协议处理程序中单击“打开”按钮,则不会出现任何错误。这可能是一个信号,表明他们也无法获得外部协议处理程序的结果
我发现如果我没有注册自定义协议,chrome将在控制台日志中打印“因为该方案没有注册的处理程序”
但是我们如何从javascript代码中获取shell\u集成::GetApplicationNameForProtocol(url).empty()
也请检查此处,也没有回答。为了澄清,出于隐私和安全原因,JavaScript故意不允许检测本地协议处理程序;看
此停止工作的具体原因是。使用
pagehide
事件。@wOxxOm我尝试了pagehide,但它也不起作用。有什么方法可以捕获协议未注册时出现的错误吗?我尝试了,但失败了。关于@Qiulang,你有什么消息吗
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;
}