I encountered this problem when I was looking for a proof for the Fundamental lemma of calculus of variations for $L^1 _{\text{loc}}$ functions (or the uniqueness of weak derivatives), which states
If $ f \in L^1 _{\text{loc}}(\Omega)$ and $$ \int _\Omega f(x) \phi (x) dx = 0 \quad \forall \phi \in C ^\infty _c(\Omega), $$ then $u \equiv 0$ a.e. on $\Omega$.
Detailed proof can be found here and here.
I try to summarize the proof in simple terms. Suppose $f \in L^1 _{\text{loc}}(\Omega)$. Fix $\epsilon > 0$ and let $\rho_\epsilon(x)$ to be a mollifier. Define $$ \Omega _\epsilon = \{x \in \Omega : \text{dist}(x, \partial \Omega) > \epsilon \}. $$ Then for $x \in \Omega _\epsilon$, $\phi_{\epsilon, x} (y) = \rho_\epsilon(x - y) \in C ^\infty _c(\Omega)$. Thus by the assumption, $\rho_\epsilon * f = 0$ ($*$ means convolution). We also know that $\rho _\epsilon * f \to f$ in $L^1 _\text{loc} (\Omega)$, so a subsequence $0 \equiv (\rho _\epsilon * f)_k \to f$ a.e. on a compact subset of $\Omega$. As this holds for all compact subsets of $\Omega$, the proof concludes that $f \equiv 0$ a.e. in $\Omega$.
I do not understand the last statement, i.e. if $f \equiv 0$ over all compact subset, by what can we conclude that $f \equiv 0$ over the whole set?
Any help is appreciated.