The following theorem (picture below) is from Peres-Morters book: Brownian motion.
Consider an open $O \subset \mathbb{R}^d$ and a $C^2$-function $f: \overline{O} \to \mathbb{R}$ such that for every $(x,r) \in O \times \mathbb{R}_+,E_x[|f(B_r)|]<\infty$ and $E_x[\int_0^r |\Delta f(B_u)|]<\infty.$ Let $T:=\inf \{ r \in \mathbb{R}_+,B_r \notin O \}.$
We want to prove that for every $x \in O,f(B_{r \wedge T})-\frac{1}{2}\int_0^{r \wedge T} \Delta f(B_u) du$ is a $P_x$-martingale.
Is it possible to do that using the same argument of Theorem $2.51$ below?

Yes, this can be proved in the same way. As noted in the comments, when $f$ is harmonic the second term vanishes.