Why doesn't the localization map $A \to A_f$ show that open embeddings of schemes are not always monomorphisms? Suppose $\iota: X \hookrightarrow Y$ is an open embedding of schemes. We can assume $X$ is an open subscheme of $Y$.
On the level of sets, $\iota$ is injective.
I wish to see that the pullback map $\iota^\sharp: \mathcal O_Y \to \mathcal O_Y|_X$ is injective.
I don't see how this is always true.
For example, if we take a ring $A$ which is not a domain, then the localization (restriction) map $A \to A_f$ is not always injective.
Doesn't this show that open embedding are not always monomorphisms?
If not, where is the error?

I deleted my previous answer, as it seemed it didn't truly address the question. Nevertheless, I think there are some facts related to open immersions and monomorphisms that seem relevant to this situation.
In this stacks article you'll find that a morphism of $X \to Y$ of schemes is a monomorphism if and only if the diagonal morphism
$$X \longrightarrow X \times_Y X$$
is an isomorphism. Heuristically, this is saying that a morphism is a monomorphism if and only if the self-intersection of the image is the image itself. Put in this way, it should be at least intuitively clear that an open immersion is a monomorphism.
If we restrict to the category $\mathbf{Aff}$ of affine schemes, the condition that $X \to Y$ is a monomorphism may be rephrased slightly differently. Recall that there is an equivalence of categories
$$\mathbf{Rings}^{op} \longrightarrow \mathbf{Aff}$$
given by associating to a commutative unital ring its spectrum. It follows that a monomorphism $\operatorname{Spec}(B) \longrightarrow \operatorname{Spec}(A)$
in the category of affine schemes corresponds to an $\textit{epimorphism}$
$A \longrightarrow B$ in the category of commutative unital rings. It is therefore a fact (and exercise) that any localization $A \to S^{-1}A$ is an epimorphism in $\mathbf{Rings}$.
Just a word of clarification in case it's not obvious already: while all monomorphisms of rings are injections, it is not true that all epimorphisms of rings are surjections.
