Chiral anomaly is computed very elegantly by Fujikawa method, which is also presented in Section 22.2 of Weinberg QFT textbook volume 2 or wikipedia.
Here, the underlying spacetime is assumed to be $\mathbb{R}^d$ (with $d=4$ in particular), which is contractible and therefore only trivial bundles are possble on it.
However, chiral anomaly leads to (a version) of the Index Theorem as in formula (22.2.49) in the aforementioned Weinberg book, implying that nontrivial topological configurations of the gauge fields are possible.
And this PE post says that nontrivial topologies of the gauge fields on $\mathbb{R}^4$ depend on asymptotic behavior at infinity, so that we can define them on $S^4$, the one-point compactification of $\mathbb{R}^4$.
So...I think there must be (very implicit) assumptions on asymptotic behavior of the gauge fields in the Fujikawa method, but I cannot figure out what those assumptions are and where they apply.
Could anyone please clarify for me?