Hartshorne's proof of the birational invariance of the geometric genus I am confused about a couple of steps in the proof of the birational invariance of the geometric genus (Theorem II.8.19 in Hartshorne's Algebraic Geometry).
I shall sketch the proof and highlight my doubts.
Let $X,X'$ be two birationally equivalent nonsingular projective varieties over a field k.
Hence there is a birational map $X-->X'$ represented by a morphism $f:V\rightarrow X'$ for some largest open subset $V\subset X$.
Along taxonomic lines, the proof goes like this:


*

*We first prove that $f$ induces an injective map $f^{\ast}:\Gamma(X',\omega_{X'})\rightarrow \Gamma(V,\omega_V)$

*Then we prove that the restriction map $\Gamma(X,\omega_X)\rightarrow \Gamma(V,\omega_V)$ is bijective, using the valuative criterion of properness.


From this it follows that $\rho_g(X')\leq \rho_g(X)$, and the reverse inequality follows by simmetry.
In the proof of step 1: the map $f$ induces an isomorphism $U\cong f(U)$ for some open subset $U\subset V\subset X$ and then Hartshorne claims that this implies that f induces an isomorphism $\omega_{V|U}\cong \omega_{X'|f(U)}$. Why is that?
In the proof of step 2: from the valuative criterion of properness it follows that $\textrm{codim }(X\setminus V,X)\geq 2$. In order to prove that $\Gamma(X,\omega_X)\rightarrow \Gamma(V,\omega_V)$ is bijective it suffices to prove it on open sets $U\subset X$ trivializing the canonical sheaf $\omega_{X|U}\cong \mathcal{O}$, namely that $\Gamma(U,\mathcal{O}_U)\rightarrow  \Gamma(U\cap V,\mathcal{O}_U\cap V)$ is bijective.
Since $X$ is nonsingular, from the first remark in the previous paragraph we have that $\textrm{codim }(U\setminus U\cap V,U)\geq 2$ and then Hartsorne claims that the result (bijectivity) follows immediately from the fact that for an integrally closed Noetherian domain $A$, we have $A=\bigcap_{\textrm{ht } \mathfrak{p}=1} A_{\mathfrak{p}}$. I do not see this either.
Thanks in advance for any insight.
 A: Since $U\cong f(U)=:W$ under the isomorphism guaranteed by birationality condition, we get that there is an induced isomorphism $f^*\omega_W\to \omega_U$. This follows from the fact that a morphism of (say) varieties $f:X\to Y$ induces a map $f^*\Omega^1_{Y/k}\to \Omega^1_{X/k}$ of the cotangent sheaves. Taking wedge powers gives the morphism $f^*\omega_Y\to \omega_X$. By functoriality of the cotangent sheaf, we can conclude that an isomorphism of varieties induces an isomorphism of the cotangent sheaves and hence of the canonical bundles.
Also, the cotangent sheaf (and hence the canonical sheaf) is compatible with restrictions as in Donu's comment above. So, the birational map induces the isomorphism $f^*\omega_{X'}|_W\cong f^*\omega_W\to \omega_U\cong\omega_X|_U.$ Pretty much all of this is in Chapter 2 Section 8 of Hartshorne explicitly or implicitly.
As for the second question, the important fact is the following:

Let $X$ be a normal variety with $f\in K(X)$ such that $f\in \mathcal{O}_X(U)$ where $X\setminus U$ is codimension $\ge 2$ in $X$. Then $f$ is in fact in $\mathcal{O}_X(X)\subseteq K(X)$.

Proof: Let $V=\mathrm{spec}A$ denote an affine open. $V\cap U$ has codimension at least $2$ in $V$. So, $f\in A_{\frak{p}}$ for all $\mathfrak{p}$ of height $1$ (codimension $1$). So, $f\in \bigcap_{\frak{p}:\mathrm{ht}(\mathfrak{p})=1}\mathfrak{p}=A$ by the fact cited in Hartshorne. In particular, $f$ is actually regular on all of $V$. Noting that $X$ is covered by such affine opens, we see that $f$ is actually regular everywhere and hence in $\mathcal{O}_X(X)$.
This lets us extend rational sections of line bundles defined on open subsets with complements of codimension at least $2$. Indeed, let $\mathcal{L}$ denote a line bundle on a normal $X$ as above. Let $s\in \Gamma(U,\mathcal{L})$ for $X\setminus U$ of codimension $\ge 2$. Then choose $V$ an affine open that is trivializing for $\mathcal{L}$ so that $\mathcal{L}|_V\cong \mathcal{O}_V$. Then $s$ determines a regular function $t\in \mathcal{O}_V(U\cap V)=\mathcal{O}_X(U\cap V)$. Since $U\cap V$ has codimension $\ge 2$ complement in $V$, we can extend $t$ to $\mathcal{O}_V(V)$. Hence, we can do the same for $s$. Proceeding as before, we get that $s$ extends to all of $X$.
A: I am not sure that this proof is correct for the following reason.  If $ X^{‘} $ is a non-singular surface and $ X $ is the blow-up of the surface at a non-singular point, then the sub-variety $ X \setminus V $ has codimension one in $ X $.  This contradicts the result of step two, which says that $ X \setminus V $ is a closed set of codimension greater than or equal to two.  In a thread, I asked about a generalization, and there is a possible revision of this proof that fixes this.
