GithubHelp home page GithubHelp logo

Comments (12)

matthiassommer avatar matthiassommer commented on July 18, 2024 3

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();
                    }
                }

from custom-protocol-detection.

w8w8w8 avatar w8w8w8 commented on July 18, 2024 1

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();
	//}
}

}`

from custom-protocol-detection.

Monkey-Island avatar Monkey-Island commented on July 18, 2024 1

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

from custom-protocol-detection.

agoodcoolman avatar agoodcoolman commented on July 18, 2024 1

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

from custom-protocol-detection.

agoodcoolman avatar agoodcoolman commented on July 18, 2024

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();
        }
    }
}

from custom-protocol-detection.

ivictbor avatar ivictbor commented on July 18, 2024

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

from custom-protocol-detection.

renaatdemuynck avatar renaatdemuynck commented on July 18, 2024

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

from custom-protocol-detection.

HeimMatthias avatar HeimMatthias commented on July 18, 2024

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.

from custom-protocol-detection.

git-kks avatar git-kks commented on July 18, 2024

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

from custom-protocol-detection.

Emiya0306 avatar Emiya0306 commented on July 18, 2024

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);
}

from custom-protocol-detection.

mystery3136 avatar mystery3136 commented on July 18, 2024

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

from custom-protocol-detection.

mystery3136 avatar mystery3136 commented on July 18, 2024

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 ?

from custom-protocol-detection.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.