I'd like to numerically plot the function
$$f(x)=\cos(x)\int^x_0\frac{\sin t}{\cos ^2(t) \sqrt{2+\sin^{2}\left(t\right)}}dt \tag{1}$$
I can plot this analytically by evaluating the integral in $(1)$;
$$f(x)=\frac{\sqrt{2+\sin^{2}\left(x\right)}}{3}-\frac{\sqrt{2}\cos\left(x\right)}{3} \tag{2}$$
which exists on the range $(0,\pi)$. The problem is when I want to numerically plot this function from equation $(1)$ without explicitly integrating the integral in $(1)$.
I ask this because I would like to plot similar functions for powers other than $2$ and $1/2$, for example I would like to plot
$$f(x)=\cos(x)\int^x_0\frac{\sin t}{\cos ^2(t) \sqrt[m]{2+\sin^{m}\left(t\right)}}dt \tag{3}$$
but for larger powers the integral doesn't exist in closed form and so a nice formula like eq $(2)$ cannot be used and the plotting needs to be done numerically.
When I try and plot this numerically, for example by plotting $(1)$ with Desmos, the function is only defined up to $x=\frac{\pi}{2}$.
See the image below where I compare the numerical plot of $(1)$ in blue with the analytic plot of $(2)$ in red.
The integral in $(1)$ diverges as $x\to\frac{\pi}{2}$ however because $\cos x \to 0$ in the limit $f(\frac{\pi}{2})$ is finite, I think because of the diverging integral my plotter registers the value of $(1)$ as undefined and stops plotting once the plotter reaches this point. Is there a way to plot this function in its entirety numerically?
Any suggestions would be welcome.