\documentclass[12pt,a4paper]{article}
\usepackage[margin=2cm,a4paper]{geometry}
\usepackage{parskip}
\usepackage{hyperref}
\title{Getting psfrag to work in pdflatex }
\usepackage[T1]{fontenc}
\usepackage{ebgaramond}
\usepackage{newtxmath}
\usepackage{graphicx}
\usepackage{pstool}
% \usepackage{epstopdf}
\begin{document}
You will still need a \texttt{.eps} image file; there is no \texttt{pdffrag} package that works for \texttt{.pdf} files.
Don't use the \texttt{[process=all]} option for \texttt{pstool}; that'll cause an infinite loop in Overleaf's build tool for now; sorry! If your \verb|\psfrag| replacements change but the \texttt{.eps} file itself has not been updated, you'll have to do a `recompile from scratch' to re-generate the replacements correctly.
Alternatively, you may want to work out all the \verb|\psfrag| commands in a separate project with \verb|\usepackage{psfrag}| and the LaTeX+dvipdf engine (see \url{https://www.overleaf.com/latex/examples/psfrag-example/tggxhgzwrzhn}), and once you've finalised that, copy the code into your main project (using pdflatex) and replace with \verb|\usepackage{pstool}| and \verb|\psfragfig| instead.
\begin{figure}[h!]
\centering
\psfragfig[width=0.6\linewidth]{example}{%
\psfrag{p1}{$p_1$}
\psfrag{p2}{$p_2$}
\psfrag{p3}{$p_3$}
\psfrag{\\tex[B][B]\{Plot of \$\\sin(t)\$ and \$\\cos(t)\$\}}{Plot of $\sin(t)$ and $\cos(t)$}
\psfrag{\\tex[t][t]\{\$t\$\}}{$t$}
\psfrag{\\tex[B][B]\{\$\\sin(t)\$, \$\\cos(t)\$\}}{$\sin(t)$, $\cos(t)$}
\psfrag{-1}{-1}
\psfrag{-0.2}{-0.2}
\psfrag{-0.4}{-0.4}
\psfrag{-0.6}{-0.6}
\psfrag{-0.8}{-0.8}
\psfrag{0}{0}
\psfrag{0.2}{0.2}
\psfrag{0.4}{0.4}
\psfrag{0.6}{0.6}
\psfrag{0.8}{0.8}
\psfrag{1}{1}
\psfrag{2}{2}
\psfrag{4}{4}
\psfrag{6}{6}
\psfrag{8}{8}
\psfrag{10}{10}
}
% \includegraphics[width=.6\linewidth]{example}
\caption{The same EPS image with psfragfig}
\end{figure}
\end{document}