I am trying to understand a bit better what atbegshi and lineno do (or accomplish). In the following example, I add the current linenumber to the shipout and am struggling to fully understand what's going on.
\documentclass{article}
\usepackage{lipsum}
\usepackage{atbegshi}
\usepackage[pagewise]{lineno}
\usepackage{tikz} % only for illustration
\begin{document}
\linenumbers
\AtBeginShipout{\AtBeginShipoutAddToBox{\fbox{\arabic{linenumber}}
\tikz[overlay,remember picture]{\draw[thick,blue,latex-](lastline)--++(-2cm,0);}}}
\renewcommand\thelinenumber{\arabic{linenumber}%
\tikz[overlay,remember picture]{\node(lastline){\strut};}}
\begin{itemize}
\item \lipsum*[1]
\item \lipsum*[2]
\item \lipsum*[3]
\item \lipsum*[4]
\item \lipsum*[5]
\item \lipsum*[6]
\item \lipsum*[7]
\item \lipsum*[8]
\item \lipsum*[9]
\item \lipsum*[10]
\item \lipsum*[11]
\item \lipsum*[12]
\item \lipsum*[13]
\end{itemize}
\lipsum[1-10]
\end{document}
On the first page, I get the result 44, which is too large by one, whereas on the second page I get 87, which is correct. I sort of think to understand why this is happening: in the first case, TeX decides later to move the last line to the next page, but in the second case there is no need for that. Now I am wondering if there is a way to cure this. (It is also somewhat surprising that the line number keeps growing despite the pagewise option, and if someone knows an elegant fix I'd be eager to learn as I can only think of an ugly fix at this point.)
In addition, I define nodes with TikZ. Knowing that this is bad practice, I keep on overwriting these nodes, and I wish to mark the last line (number) using \AtBeginShipout. However, I get a crazy pattern, either the last or the first line get marked. Most likely the reason is the same as above, and presumably the issue is gone once the first part of the question is solved.
What could this be good for? Among other things, one may finally answer this question, but really I wish this way to access the area filled by text.

