Issue with Accessibility Visible Text Range

I am trying to draw NSPanels on texts of other apps using AXObserverAddNotification with the attribute of kAXValueChangedNotification on an AXTextArea

I need to detect if the text range on that text area is visible on the screen and I use kAXVisibleCharacterRangeAttribute to get the visible text range but it doesn't include the top bar of the app and gives a range that starts from an index that is not visible.

This makes the panels drawn on top of the app's top app bar when scrolled to bottom like this gif

How do I exclude the top app bar for visible text range?