ismailhabib / custom-protocol-detection Goto Github PK
View Code? Open in Web Editor NEWDetect whether a custom protocol is available in browser (FF, Chrome, IE8, IE9, IE10, IE11, and Edge)
License: MIT License
Detect whether a custom protocol is available in browser (FF, Chrome, IE8, IE9, IE10, IE11, and Edge)
License: MIT License
When browser is redirected to custom protocol link it shows the custom protocol handler confirmation dialog like this one in Safari:
Unfortunately, right now the lib does not capture this, e.g. fires success callback right away when the dialog is shown (assuming that protocol has been handled).
In reality if user refuses to launch the app some extra actions may be needed so we should somehow detect acceptance and fire some callbacks.
I was using the plugin and it was working fine until we merged it and push to prod. Using the plugin in PROD environment I am having this error:
"Uncaught SyntaxError: Lexical declaration cannot appear in a single-statement context"
Accordingly with Chrome inspector it starts at else if(document.hasFocus())g();else var h=r(window,"focus",(function()
Any suggestion on how to proceed?
I am doing a simple import of your project: import customProtocolCheck from "custom-protocol-check";
This project definitely need automated tests which will check the functionality on various browsers. Manual tests are too error prone and time consuming.
What I have in mind:
I'm currently experiencing an issue with Chrome (build 49.0.2623.87) and a custom protocol on both Windows 8 and Windows 10.
The first time the custom protocol is used in Chrome, Chrome shows an External Protocol Request popup that ask if the user wants to 'Launch the Application' and has a check box to 'Remember my choice for all links of this type.' If the check box is selected, Chrome will open the application with the custom protocol links in the future. All fine so far.
Afterwards, if you uninstall the application and custom protocol, the failure callback function isn't called when you try to use the custom protocol. Chrome instead shows a popup 'No apps are installed to open this type of link (CUSTOM PROTOCOL)' and prompts the user to look for an app in the Windows Store. This popup steals the focus.
From my research, I did find a solution that involves editing C:\Users{USERNAME}\AppData\Local\Google\Chrome\User Data\Local State (more details here), but it would be great if this could be handled by custom-protocol-detection.
Does anyone else find that if you click the above option for protocols being launched, the onBlur method being used in Chrome doesn't call and you always end up running failureCallback?
I noticed there isn't anything for safari. So instead I used what Chrome was using and it works perfectly. I would suggest to put this into the package as it was very helpful. Although if the app doesn't exist this is where I am having a problem. So it would be great to have safari support soon.
For the Firefox-Version 64.0 the check stopped working.
The Function openUriUsingFirefox should throw an Exception in Lines 85/86 if the protocol is not available, but in this version of firefox did´t.
If I call the protocol in a tab, the connection fails as expected after a short time.
For a workaround the function openUriWithHiddenFrame should work with the timeout of 1second build in. So I check the firefox version and switch it:
if (browser.isFirefox) {
if (getFirefoxVersion() >= 64) {
openUriWithHiddenFrame(uri, failCallback, successCallback);
} else {
openUriUsingFirefox(uri, failCallback, successCallback);
}
} else if ...
The function openUriUsingFirefox don't take effect in latest edition Firefox(74.0),however openUriWithHiddenFrame do the work
Since the release of firefox 53 the openUriUsingFirefox function, iframe.contentWindow.location.href = uri; don't throw any exception anymore.
failCb() is not called and successCb() transport the user to the Windows Store to open an unknown protocol (on windows 10) or nothing on windows <10 & mac.
Do you have any workaround about re-adding firefox support?
See:
https://msdn.microsoft.com/en-us/library/jj154912(v=vs.85).aspx
Regards,
Arfy
Protocol detection in IE11 in Windows 7 doesn't work
Html page:
<html>
<head>
<script src="protocolcheck.js"></script>
</head>
<body>
<script>
protocolCheck('mytest:100:1',
function() {
console.log("Failure!");
}, function() {
console.log("Success!");
}
);
</script>
</body>
</html>
My application successfully launches a new window, but onblur event never happens, so fail callback is always executed.
Chrome and Edge are still not compatible with a custom handler, i have windows 10.
Firefox, Opera, Safari all work fine.
Is it planned to support Safari (on Mac OS X)?
SEP: Symantec Endpoint Portection 11 with latest virus definitions.
Hi Ismailhabib,
One of my teams would like to use your custom-protocol-detection library in a project, though is unable to without a specific OSS license being stipulated.
Would you be open to the idea of adding a license like MIT or Apache 2.0 to this project?
Thank you for this fantastic bit of software engineering, sir!
uri随便传值,iframe.contentWindow.location.href = uri ,传入的值能打开软件就打开软件,打不开软件什么都不做,也不触发失败的回调
Steps:
<html>
<head>
<script src="protocolcheck.js"></script>
</head>
<body>
<script>
function test() {
protocolCheck('blablabla', function() { alert("Failure!"); }, function() { alert("Success!"); } );
}
</script>
<button onclick="test()">Test</button>
</body>
</html>
Expected result:
Failure callback is executed.
Actual result:
Failure and Success callbacks are executed.
Solution:
In openUriWithHiddenFrame
function change order of lines in timeout function.
From:
var timeout = setTimeout(function () {
failCb();
handler.remove();
}, 1000);
to
var timeout = setTimeout(function () {
handler.remove();
failCb();
}, 1000);
Also, it's better to do the same in detection code for Chrome (openUriWithTimeoutHack
function).
Because of browser detection ifs
in Safari nothing is launched, neither success nor fail callback:
https://github.com/ismailhabib/custom-protocol-detection/blob/master/protocolcheck.js#L197
if (navigator.msLaunchUri) { //for IE and Edge in Win 8 and Win 10
openUriWithMsLaunchUri(uri, failCb, successCb);
} else {
var browser = checkBrowser();
if (browser.isFirefox) {
openUriUsingFirefox(uri, failCallback, successCallback);
} else if (browser.isChrome) {
openUriWithTimeoutHack(uri, failCallback, successCallback);
} else if (browser.isIE) {
openUriUsingIEInOlderWindows(uri, failCallback, successCallback);
} else {
//not supported, implement please
}
}
Instead of commented line a failure callback has to be called or a new, third type has to be introduced.
Moreover the check returns following browser object:
isChrome: false
isFirefox: false
isIE: false
isOpera: false
isSafari: false
Safari version is 10.1.2 (12603.3.8).
Consider change below. This is because if protocol is registered but app is not there then firefox throws another error e.name==NS_ERROR_FAILURE
if (e.name == "NS_ERROR_UNKNOWN_PROTOCOL") {
failCb();
}
to
if (e ) {
failCb();
}
window.protocolCheck = function(uri, failCb, successCb) {
...
openUriWithMsLaunchUri(url, failCb, successCb);
should be uri, not url - otherwise, edge throws 'url is undefined'
Awesome library. Thank you! I'd buy you a beer if I could.
Could you implement a successCb
analog to failCb
? successCb
should be called when the custom protocol has been recognized.
This would help to inform users that the external application has been started.
We have applications that are sometimes slow to launch for some users. Having the ability to control the timeouts would be very helpful in these cases.
I'll create a pull request for this.
Thanks!
Nate
If protocol is defined and it is associated with an executable, browser shows an alert in order to accept or deny the execution.
I think that alert causes the timeout to occur so the failure callback is called, instead of the success callback.
Have you checked this?
I am in Google Chrome.
Thanks
Jaime
Custom protocol detection succeeds even when there is no app handler for it on Firefox 57 MacOS.
Hi there, first off this js file is really useful, great job on it. I have run across a problem though now that I have implemented it my self. Details below:
Chrome ver. 42.0.2311.90 m / Windows
If a user selects the "Remember my choice for all links of this type" check box in the browser default protocol handler alert from there on when ever the protocolCheck method is called it will always run the fail callback as well as opening the app associated with the protocol handler. I believe this is due to the time out checking on if that dialog opens or not after a certain amount of time, but have not had the opportunity to dig further into the issue.
function openUriWithTimeoutHack(uri, failCb, successCb) {
var timeout = setTimeout(function () {
failCb();
handler.remove();
}, 1000);
//handle page running in an iframe (blur must be registered with top level window)
var target = window;
while (target != target.parent) {
target = target.parent;
}
var handler = _registerEvent(target, "blur", onBlur);
function onBlur() {
clearTimeout(timeout);
handler.remove();
successCb();
}
window.location = uri;
}
thanks
This project is amazing!!! I like the way you used onBlur for Chrome.
I'm having a problem with msLaunchUri in Edge on Windows 10 (obviously) but the problem doesn't appear in IE on Win10. In IE it works as designed, calling the success and fail functions properly. But in Edge, nothing happens at all. I've modified your code slightly (as I can't use jquery to call your functions) and here it is:
if (navigator.msLaunchUri) { alert('msLaunchUri is true'); navigator.msLaunchUri(url, function(){ console.log('dwrc protocol found'); }, //success function(){ startAutoDownload(url); } //failure );
The alert fires, so I know the if statement is working. I also can see from the F12 menu that the url value is correct. But the program doesn't launch, nothing gets written to the console, and the download doesn't start. Even though the exact same code works in IE.
Any ideas?
P.S. how do I get the line breaks in my code to show in the post?
Currently I managed to make it work in Safari with a
tag, should I do it with div
as in examples for better compatibility or can keep it? Also, I think index.js
file is not in use and should be removed.
Hi
Probably need a special registration of the new protocol in the register of Windows?
Open the client's API for success or failure callback
uri传什么?
Steps:
Expected result:
Fail callback is executed.
Actual result:
Success callback is executed. Nothing is invoked.
Workaround:
Open "about:preferences#applications" and set your protocol as "Always ask".
Similar issue (see #8) exists also in Chrome (Windows 8 and 10).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.