If I understand you correctly, why are you not using the out of box functionality to enrich the Caption of a tab page with a badge that Mendix introduced in 8.13.2? Using the Edit button can use parameters from the context the widget is placed in.
Try with this count badge widget it will fulfill your requirement
Added sample screenshot for your reference.
I've worked with this widget in the past, Tab Extension https://marketplace.mendix.com/link/component/894
Might need some work though to get it running in 9.