How to update the browser in Selenium Webdriver

How to connect Selenium Webdriver to existing Firefox / Chrome browser session?

This might be a repeated question but I couldn't find any solution. Recently I found a related post Connecting Selenium WebDriver to an existing browser session but people suggested me to ask a new question.

If any one have tried connecting selenium webdriver to an existing browser session that was earlier spawned by selenium itself and had success in doing so, please let me know.

I could find a couple of suggestions to try on firefox and selenium 2.X version. But those suggestions do not work for selenium 3.X and there are no solutions for chrome browser.

I have tried all suggestions for Selenium 25.3, firefox v 46 and it works. But for Chrome with chrome driver, I am not able to make it work.

Edited:

Here is the code I have tried:

Starting a firefox driver

Copied RemoteWebDriver source code and changed capabilities from private to protected.

Created a new class RemoteDriverEx extending the copied RemoteWebDriver class Changed the NEW_SESSION command issued by the original driver to GET_CURRENT_URL

Then a JUnit test to verify

But I am struck with exception

Full code shared @ https://drive.google.com/open?id=0Bz2XxuQQc24KdHVqR3BPaXowUnM