Configure Selenium EdgeDriver to prevent uri/protocol_handler popups.

I just spend a few hours on this, so here’s a quick public not for anyone trying to do selenium testing on Microsoft Edge Chromium that runs into a popup for custom uri-handlers:

You can disable them by passing the following code-block as experimental options in microsoft edge.

{	"protocol_handler": {
		"allowed_origin_protocol_pairs": {
			"https://www.ivojonker.nl.nl": {
				"myUriHandler": true
			}
		}
	}
}

Here’s my proof of concept / quick and dirty implementation in java:

		EdgeDriver driver = null;
		EdgeOptions opt=new EdgeOptions();

		String protocolHandlerSetting="	{\"protocol_handler\": {\r\n"
			+ "		\"allowed_origin_protocol_pairs\": {\r\n"
			+ "			\"https://www.ivojonker.nl\": {\r\n"
			+ "				\"myUriHandler\": true\r\n"
			+ "			}\r\n"
			+ "		}\r\n"
			+ "	}}";
		
		opt.setExperimentalOption("prefs", new Gson().fromJson(protocolHandlerSetting, HashMap.class));
		
		driver = new EdgeDriver(opt);
		driver.get("https://www.ivojonker.nl");

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *