$f(R)$ gravity is one of the simplest generalizations of general relativity, which may explain the accelerated cosmic expansion without introducing a cosmological constant. Transformed into the Einstein frame, a new scalar degree of freedom appears and it couples with matter fields. In order for $f(R)$ theories to pass the local tests of general relativity, it has been known that the chameleon mechanism with a so-called thin-shell solution must operate. If the thin-shell constraint is applied to a cosmological situation, it has been claimed that the equation-of-state parameter of dark energy $w$ must be extremely close to $\ensuremath{-}1$. We argue this is due to the incorrect use of the Poisson equation, which is valid only in the static case. By solving the correct Klein-Gordon equation perturbatively, we show that a thin-shell solution exists even if $w$ deviates appreciably from $\ensuremath{-}1$.