custom-protocol-detection icon indicating copy to clipboard operation
custom-protocol-detection copied to clipboard

Firefox Version 64.0

Open heural opened this issue 5 years ago • 12 comments

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 ...

heural avatar Jan 03 '19 14:01 heural

I using this code ,and it work

`function openUriUsingFirefox(uri, failCb, successCb) { var iframe = document.querySelector("#hiddenIframe");

if (!iframe) {
    iframe = _createHiddenIframe(document.body, "about:blank");
}

try {
    iframe.contentWindow.location.href = uri;
	
	if(iframe.contentWindow.location.protocol=="about:"){
		successCb();
	}else{
		failCb();
	}
} catch (e) {
	failCb();
    //if (e.name == "NS_ERROR_UNKNOWN_PROTOCOL") {
    //    failCb();
    //}
	//if(e.name=="SecurityError"){
	//	failCb();
	//}
}

}`

w8w8w8 avatar May 30 '19 10:05 w8w8w8

I'm using version 67.0 , and it seems that it does not work.

Monkey-Island avatar Jul 02 '19 14:07 Monkey-Island

I'm using firefox 67.0.4 windows ,it seems that it does not work.

agoodcoolman avatar Jul 12 '19 15:07 agoodcoolman

i'm using w8w8w8 code, it's not perfect,i need twice click using the his code.

i'm using blew code, and it's work for me .i don't know why is it.

function openUriUsingFirefox(uri, failCb, successCb) {
    var iframe = document.querySelector("#hiddenIframe");

    if (!iframe) {
        iframe = _createHiddenIframe(document.body, "about:blank");
    }

    try {
 
            iframe.contentWindow.location.href = uri;
        iframe.contentWindow.onload = function () {
                
            }
            

    } catch (e) {
        failCb();
        if (e.name == "NS_ERROR_UNKNOWN_PROTOCOL") {
            failCb();
        }
    }
}

agoodcoolman avatar Jul 15 '19 16:07 agoodcoolman

custom-protocol-detection is not working in 68.0.2 (64-bit) Windows 64. When protocol is not register it fires success callback

ivictbor avatar Aug 24 '19 10:08 ivictbor

Detection is not working in 74.0b9 (64-bit) on Windows 10 x64. It always fires success callback.

renaatdemuynck avatar Mar 17 '20 20:03 renaatdemuynck

Improved code, works with FF74:

`function openUriUsingFirefox(uri, failCb, successCb) { var iframe = document.querySelector("#hiddenIframe");

if (!iframe) {
	iframe = _createHiddenIframe(document.body, "about:blank");
}
try {
	iframe.contentWindow.location.href = uri;
	var timeout = setTimeout(function () {
		try {
			if(iframe.contentWindow.location.protocol=="about:"){
				
				successCb();
			}else{

				failCb();
			}
		} catch (e) {
			if (e.name == "NS_ERROR_UNKNOWN_PROTOCOL") {
				failCb();
			}
			if(e.name=="SecurityError"){
				failCb();
			}
		}
	}, 100);
	
} catch (e) {
	if (e.name == "NS_ERROR_UNKNOWN_PROTOCOL") {
		failCb();
	}
	if(e.name=="SecurityError"){
		failCb();
	}
}

}`

The solution is to use a timeout after calling the protocol, as FF will not fire an error when the protocol of the frame is checked straightaway. This is why it required two clicks in the solution above: After the first click, the immediate check did not yet return before Firefox finished calling the protocol's location. With the second click, the location.protocol from the first call is firmly in place and returned the error immediately. The 100ms wait takes this into account.

HeimMatthias avatar Apr 01 '20 19:04 HeimMatthias

I got it to work with this function

                if (!iframe) {
                    iframe = _createHiddenIframe(document.body, "about:blank");
                }

                try {
                    iframe.contentWindow.location.href = uri;
                    setTimeout(function () {
                        try {
                            if (iframe.contentWindow.location.protocol === "about:") {
                                successCb();
                            } else {
                                failCb();
                            }
                        } catch (e) {
                            if (e.name === "NS_ERROR_UNKNOWN_PROTOCOL" || e.name === "NS_ERROR_FAILURE" || e.name === "SecurityError") {
                                failCb();
                            }
                        }
                    }, 500);
                } catch (e) {
                    if (e.name === "NS_ERROR_UNKNOWN_PROTOCOL" || e.name === "NS_ERROR_FAILURE" || e.name === "SecurityError") {
                        failCb();
                    }
                }

matthiassommer avatar Apr 22 '20 18:04 matthiassommer

i tried using matthiassommer code, but it is not working, win10 and FF98

git-kks avatar Mar 18 '22 09:03 git-kks

i tried using matthiassommer code, but it is not working, win10 and FF98

@git-kks I just improve the code from @matthiassommer, it works on mac FF111.0.1.

function openUriUsingFirefox(uri, failCb, successCb) {
    var iframe = document.querySelector("#hiddenIframe");

    if (!iframe) {
        iframe = _createHiddenIframe(document.body, "about:blank");
        iframe.contentWindow.location.href = uri;
    }

    setTimeout(function() {
        try {
            iframe.contentWindow.location.href = uri;
            try {
                if (iframe.contentWindow.location.protocol === "about:") {
                    successCb();
                } else {
                    failCb();
                }
            } catch (e) {
                if (e.name === "NS_ERROR_UNKNOWN_PROTOCOL" || e.name === "NS_ERROR_FAILURE" || e.name === "SecurityError") {
                    failCb();
                }
            }
        } catch (e) {
            if (e.name == "NS_ERROR_UNKNOWN_PROTOCOL") {
                failCb();
            }
        }
    }, 200);
}

Emiya0306 avatar Mar 23 '23 07:03 Emiya0306

After checking the box Always open such links in associated apps on the popup the chrome blur methods doesn't work. Because next time when user checks for custom protocol it automatically opens the app due to which focus is not stolen from the browser and fail call back also gets triggered. Hidden Iframe method doesn't work with chrome. Is there a workaround for chrome ? @Emiya0306 @matthiassommer

mystery3136 avatar Apr 02 '23 21:04 mystery3136

i tried using matthiassommer code, but it is not working, win10 and FF98

@git-kks I just improve the code from @matthiassommer, it works on mac FF111.0.1.

function openUriUsingFirefox(uri, failCb, successCb) {
    var iframe = document.querySelector("#hiddenIframe");

    if (!iframe) {
        iframe = _createHiddenIframe(document.body, "about:blank");
        iframe.contentWindow.location.href = uri;
    }

    setTimeout(function() {
        try {
            iframe.contentWindow.location.href = uri;
            try {
                if (iframe.contentWindow.location.protocol === "about:") {
                    successCb();
                } else {
                    failCb();
                }
            } catch (e) {
                if (e.name === "NS_ERROR_UNKNOWN_PROTOCOL" || e.name === "NS_ERROR_FAILURE" || e.name === "SecurityError") {
                    failCb();
                }
            }
        } catch (e) {
            if (e.name == "NS_ERROR_UNKNOWN_PROTOCOL") {
                failCb();
            }
        }
    }, 200);
}

Can it work with chrome ?

mystery3136 avatar Apr 08 '23 21:04 mystery3136