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.

So i found a way to plot it by using integration by parts to pull the divergent part of the integrand out of the integral. By taking
$$u=\frac{\sin(x)}{\sqrt{2+\sin^2\left(x\right)}} \qquad \frac{dv}{dx}=\sec^2(x) \implies \frac{du}{dx}=\frac{2\cos(x)}{(2+\sin^2x)^{\frac{3}{2}}} \qquad v=\tan(x)$$
We can perform integration by parts to find
$$f(x):=\cos(x)\int^x_0\frac{\sin x}{\cos^{2}\left(x\right)\sqrt{2+\sin^2x}}dx=\frac{\sin^2x}{\sqrt{2-\sin^2x}}-\cos(x)\int^x_0\frac{2\sin x}{(2+\sin^2x)^{\frac{3}{2}}}dx$$
The divergent part of the integral has now been removed and cancelled by the $\cos (x)$ term out front of the initial integral. Since the remaining integral is finite over $(0,\pi)$ my plotter can now plot it fine.