Continued fraction estimation of error in Leibniz series for $\pi$.

The following arctan formula for $\pi$ is quite well known $$\frac{\pi}{4} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \cdots\tag{1}$$ and bears the name of Madhava-Gregory-Leibniz series after its discoverers. The formula has an easy proof via integration. While reading a paper by Ranjan Roy titled "The Discovery of the Series Formula for $\pi$ by Leibniz, Gregory and Nilakantha" I was surprised to find that error in approximation via $n$ terms of series $(1)$ can be expressed in terms of a continued fraction studied by both Rogers and Ramanujan.

Let $$f(x) = \cfrac{1}{x +\cfrac{1^{2}}{x +\cfrac{2^{2}}{x +\cfrac{3^{2}}{x + \cdots}}}}\tag{2}$$ for $x > 0$ and let $n$ be a positive integer. Let us define $S_{n}$ by $$S_{n} = \sum_{i = 1}^{n}(-1)^{i - 1}\cdot\frac{1}{2i - 1}$$ so that $S_{n}$ is the $n^{\text{th}}$ partial sum of series $(1)$. Then we have the formula $$\frac{\pi}{4} = S_{n} + (-1)^{n}\cdot\frac{f(2n)}{2}\tag{3}$$ The formula above is so marvelous that first 2-3 convergents of the continued fraction $(2)$ are sufficient to give a very good approximation of $\pi$ for small values of $n$. For example if $n = 4$ so that $$S_{4} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} = \frac{2}{3} + \frac{2}{35} = \frac{76}{105}$$ and taking 3rd convergent of $f(8)$ we see that $$f(8) \approx \cfrac{1}{8 +\cfrac{1^{2}}{8 +\cfrac{2^{2}}{8}}} = \frac{17}{138}$$ and hence $$\frac{\pi}{4} = S_{4} + \frac{f(8)}{2} \approx \frac{76}{105} + \frac{17}{276} = 0.78540372670807$$ which is greater than $\pi/4$ by approximately $5.5 \times 10^{-6}$ so that the approximation is really great.

I would like to know the proof of identity $(3)$. Any reference for the proof would also be helpful.

Update: Sorry people! I found the answer myself when I used the information in related link about the continued fraction $f(x)$. See my answer below.

On the other hand I would be more than happy if we can obtain a proof of $(3)$ without using Rogers proof mentioned in my answer. Perhaps there was some simpler proof available with Nilkantha.

We have \begin{align} \frac{\pi}{4} &= \int_{0}^{1}\frac{dt}{1 + t^{2}}\notag\\ &= \int_{0}^{1}\left(1 - t^{2} + \cdots + (-1)^{n - 1}t^{2n - 2} + (-1)^{n}\frac{t^{2n}}{1 + t^{2}}\right)\,dt\notag\\ &= 1 - \frac{1}{3} + \cdots + (-1)^{n - 1}\frac{1}{2n - 1} + (-1)^{n}\int_{0}^{1}\frac{t^{2n}}{1 + t^{2}}\,dt\notag\\ &= S_{n} + (-1)^{n}g(n)\text{ (say)}\notag \end{align} Then we have \begin{align} g(n) &= \int_{0}^{1}\frac{t^{2n}}{1 + t^{2}}\,dt\notag\\ &= \int_{0}^{\infty}\frac{e^{-2nz}}{1 + e^{-2z}}\frac{dz}{e^{z}}\text{ (by putting }t = e^{-z})\notag\\ &= \frac{1}{2}\int_{0}^{\infty}\frac{e^{-2nz}}{\cosh z}\,dz\notag\\ &= \frac{f(2n)}{2}\notag \end{align} We have $$f(x) = \int_{0}^{\infty}\frac{e^{-zx}}{\cosh z}\,dz$$ from here.
Note: While the only proof of the link between continued fraction $f(x)$ and the corresponding integral which I have is the one by Rogers (see linked question for more details on Rogers paper), I strongly believe that the continued fraction $f(x)$ was also known to Nilkantha. In fact Ranjan Roy mentions in his paper (referred in my question) that Nilkantha used "some procedure" which gave successive convergents to the continued fraction $f(x)$. I therefore believe that Nilkantha did have a proof of the link between continued fraction $f(x)$ and its integral representation well before Rogers (say in 15th-16th century).