Print page numbers in WKWebView

I am printing the contents rendered on a WKWebView using this API.

https://developer.apple.com/documentation/webkit/wkwebview/3516861-printoperationwithprintinfo?language=objc

The print preview loads fine, but I am unable to print page numbers. I tried overriding the drawPageBorderWithSize method of NSView (since WKWebView inherits from NSView) but that never gets called. I asked a question in the Apple Developer Technical Support and I was asked to use CSS styling to print page numbers. I then tried to use the following solution in CSS:

#content {
    display: table;
}

#pageFooter {
    display: table-footer-group;
}

#pageFooter:after {
    counter-increment: page;
    content: counter(page);
}

<div id="content">
  <div id="pageFooter">Page </div>
  multi-page content here...
</div>

However, when I try this I only get Page1 at the bottom of the last page. Are there any working solutions for printing page numbers using CSS styling?