Provide a way for web pages to gracefully handle invalid URL scheme exceptions

Originator:neilco
Number:rdar://12284894 Date Originated:12-Sep-2012 03:44 PM
Status:Open Resolved:
Product:iPhone/iPod Touch Product Version:5.1.1
Classification:Enhancement Reproducible:Not Applicable
 
Summary:

Currently, if a web page viewed in Mobile Safari attempts to open a URL using a custom URL scheme for an iOS application and that application has not been installed, the user is presented with a modal alert message indicating that the page cannot be opened. This enhancement request describes a mechanism to allow web developers to gracefully handle this exception. 

The primary use case is to allow to a web page to render a subset of the information that would be displayed in the application to visitors without the target application without the negative connotations of displaying a error message to visitors. 

Steps to Reproduce:

1. Create a simple web page containing the following hyperlink: <a href="fakeapp://launch">Open Fake App</a>
2. View the web page in Mobile Safari on an iPhone, iPod Touch, or iPad. 
3. Click the Open Fake App link. 
4. You will see a alert with the title "Cannot Open Page" and the message "Safari cannot open the page because the address is invalid".

Suggested Enhancement: 

The web developer should be allowed to override the default browser behaviour and provide their own mechanism for handling the scenario where the target application is not installed. 

The solution I propose is that the browser should raise a JavaScript exception prior to displaying the default exception alert. The JavaScript exception provides the web developer with the opportunity to handle the exception within their own code. This will lead to a better user experience and will give web developers the flexibility to decide what to do in the event that the target application has not been installed by the user. 

An example of the JavaScript code a developer wishing to gracefully handle the URL scheme exception may write:

<script type="text/javascript">
window.onerror = function(msg, url, line) {
	if (msg === 'Cannot Open Page') {
		// At this point, the developer can choose to ignore the exception, 
		// redirect to the App Store, or display an error page to the user. 
		
		// This line prevents the "Cannot Open Page" alert from being displayed
		return true;
	}
}
</script>
<a href="fakeapp://launch">Open Fake App</a>

Similarly, if the web page attempts to call a custom URL scheme via JavaScript, the developer may proceed as below:

<script type="text/javascript">
function tryToLaunchFakeApp() {
	try {
		window.location = "fakeapp://launch";
	} catch(e) { 
 		if (e instanceof URLSchemeException) {
			// This line prevents the "Cannot Open Page" alert from being displayed
			e.handled = true; 
		
			// At this point, the developer can choose to ignore the exception, 
			// redirect to the App Store, or display an error page to the user. 
		}
	}
}
</script>
<a href="#" onclick="tryToLaunchFakeApp()">Open Fake App</a>

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!