Мучаю AI generation уже часа полтора, никак не может выдать мне нужный код. Наверное, я хреновый prompt инженер.

I need to scroll so that the element is vertically centered on the page at Y position.
I have an element located at [[ELEM_XPATH]].
The parameters for that element include:
- ELEM_X: Integer value, offset relative to the current X window position.
- ELEM_Y: Integer value, offset relative to the current Y window position.
- ELEM_WIDTH: Integer value, offset relative to the current window position.
- ELEM_HEIGHT: Integer value, offset relative to the current window position.
It's essential to ensure that the element could be positioned at the top or bottom of the current browser view. Additionally, consider the scenario where the element is outside the current view, indicated by ELEM_Y < 0, signifying that the element is at the top of the current page but beyond the current view.
I also have information on the current resolution and cursor position:
- CURSOR_X: Current cursor coordinates X, relative to the screen position.
- CURSOR_Y: Current cursor coordinates Y, relative to the screen position.
- SCROLL_X: Current scroll X value. Combined with CURSOR_X, this value will give the absolute cursor position.
- SCROLL_Y: Current scroll Y value. Combined with CURSOR_Y, this value will give the absolute cursor position.
- BROWSER_WIDTH: Current browser viewport width, excluding space taken by the address bar or native window. Works the same as window.innerWidth.
- BROWSER_HEIGHT: Current browser viewport height, excluding space taken by the address bar or native window. Works the same as window.innerHeight.
Do not get any element params because you have them all. Create a loop where you continuously scroll a small random distance and check if the element is positioned correctly. This case also includes scrolling up on pages where ELEM_Y < 0.