Getting the viewport.offset

Is there a way to get the viewport offset used to see how far the user has scrolled down a page? I have seen it done by triggering the edit page event, that will make the sessionStorage.viewPort available. But it will also (of course) trigger an edit of the page which I do not want.

Any insights into this would be greatly appreciated, cheers!

do you ask for a way to get the last known window.pageYOffset on a given confluence page?

i did not know that this value is stored in any way. i just opened my network-monitor and found no hint that confluence is sending this information from the frontend to the backend.

can you explain where you found the sessionStorage.viewPort?

The pageYOffset is pretty straight forward. The viewPort compensates for the header and gives a reading on where on the page the user has scrolled if I am correct.

Well it is not sending it back via the network, it seems to be storing it on the window object.

If you trigger the edit event and put a breakpoint before it actually enters the editor you should be able to get it by typing sessionStorage.viewPort into your console.

Cheers, /M

i did not fully understand where you put the breakpoint.

i have two confluence instances running. 6.3.4 and 6.7.2. when i enter the editor of a long page, scroll down and reload the page, the scroll position is not restored (so it seems confluence does not store the scroll position on its own) - i am using chrome.

when i enter the editor (with my debug console open) and i try to read sessionStorage.viewPort i get “undefined”

when i scroll down in the editor, the value is still undefined.

is it possible that this value is written by some custom code or 3rd party plugin, or am i missing something?

I ended up doing some digging in the Confluence source code and found out that this is something that is done when activating the editor. TinyMCE uses it to scroll to the correct place on the page I think.

I guess what I could do is mimic the behaviour of that method instead of triggering the edit to get the position. We went for a slightly different solution in the end, but maybe I’ll get the time to revisit this soon.

Cheers for the push in the right direction @matthias.steinboeck !

1 Like