I have implemented a solution according to 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 have implemented a solution according to https://gist.github./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);
}
}
Share
Improve this question
edited Nov 3, 2020 at 10:19
Bergi
666k161 gold badges1k silver badges1.5k bronze badges
asked Nov 3, 2020 at 7:34
charitht99 pereracharitht99 perera
3356 silver badges24 bronze badges
3
-
Use
pagehide
event. – woxxom Commented Nov 3, 2020 at 9:56 - @wOxxOm I tried pagehide it did not work either. – Qiulang Commented Dec 24, 2020 at 1:44
- 1 Since chrome 89+ it works again! I also updated my answer. – Qiulang Commented Nov 11, 2021 at 10:24
2 Answers
Reset to default 3I 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./ 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
https://chromium.googlesource./chromium/src/+/master/chrome/browser/external_protocol/external_protocol_handler#119
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./chrome/thread/78279651?hl=en, no answer either.
--- update for Chrome 89+ ---
I found that onBlur
works again! I can't find a clear document for that, but from Issue 1137801: Regression: "onBlur" event is not triggered for built-in dialogs
Comment 30 by [email protected] on Wed, Mar 24, 2021, 6:43 AM GMT+8
As of v89, the original plaint here no longer repros, which means we've now introduced a privacy bug that enables protocol detection. Bisect shows that the protocol detection hack started working again
I test Chrome 90+, it does work!
To clarify, detection of local protocol handlers is intentionally not possible from JavaScript for Privacy and Security reasons; see this post.
The specific reason this stopped working is https://crbug./1137801.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744238796a4564603.html
评论列表(0条)