Chrome extension: Scroll restore after window.reload()

1,416 views
Skip to first unread message

atm0s

unread,
Nov 2, 2010, 8:35:45 PM11/2/10
to Chromium Apps
Hi..

I've written a chrome extension that changes the appearance and adds a
little extra functionality to the comments of a famous dutch Blog.

My extension has a feature that reloads the page, checks what comments
are new, and sets the scroll position to make it visible.

But the problem is, that Chrome restores the scroll position right
after that, and very unpredictable.

I tried adding delays, with setTimeout, also I tried to wait for an
onscroll event, this all made it a little better, but 1 out of 3 times
it still happens.

My question is, is there a way, to prevent Chrome from interfering
with the scroll position?

Better would be, that it doesn't restore the scroll position if some
javascript already did.

cheers,

atm0s.

Caleb Eggensperger

unread,
Nov 2, 2010, 10:02:16 PM11/2/10
to atm0s, Chromium Apps
I agree that if the scroll position has been set by javascript then Chrome shouldn't be interfering with it. You should search on crbug.com to see if a bug has been filed, and if it hasn't, you should file one (and post a link back here)

Incidentally, a better group for discussion of extensions is, naturally, chromium-...@chromium.org. You may get a better response if you post there.
--
Caleb Eggensperger
www.calebegg.com

PhistucK

unread,
Nov 3, 2010, 3:14:21 AM11/3/10
to atm0s, Chromium Apps
If you add your scrolling code to the onload handler (with a setTimeout), does it still not work?
I would do that, in addition to adding the (same) scrolling code to the DOMContentLoaded event. Sounds like it should work (perhaps a small flicker will happen, but this is a workaround, after all).

PhistucK

atm0s

unread,
Nov 3, 2010, 8:17:14 AM11/3/10
to Chromium Apps
Thanks,

I added it here: http://code.google.com/p/chromium/issues/detail?id=61674

On 3 nov, 03:02, Caleb Eggensperger <caleb...@gmail.com> wrote:
> I agree that if the scroll position has been set by javascript then Chrome
> shouldn't be interfering with it. You should search on crbug.com to see if a
> bug has been filed, and if it hasn't, you should file one (and post a link
> back here)
>
> Incidentally, a better group for discussion of extensions is, naturally,
> chromium-extensi...@chromium.org. You may get a better response if you post

atm0s

unread,
Nov 3, 2010, 8:22:40 AM11/3/10
to Chromium Apps
On 3 nov, 08:14, PhistucK <phist...@gmail.com> wrote:
> If you add your scrolling code to the onload handler (with a setTimeout),
> does it still not work?
> I would do that, in addition to adding the (same) scrolling code to the
> DOMContentLoaded event. Sounds like it should work (perhaps a small flicker
> will happen, but this is a workaround, after all).
>

I can't do it before I completely reformatted the layout of the page,
since this is what my extension does.
What I do now is:


if (atm0s.geenstijl.mozilla.extension.isFF()) {
this.initializeScrollPosition();
} else //chrome
{
// Restore or set scrollposition
this.scrolled = false;
$(window).scroll(function(e) {
if (!objRef.scrolled) {
setTimeout(function() {
if (!objRef.scrolled) {
objRef.scrolled = true;
objRef.initializeScrollPosition();
}
}, 100);
}
});

setTimeout(function() {
if (!objRef.scrolled) {
objRef.scrolled = true;
objRef.initializeScrollPosition();
}
}, 2000);
}

This makes it work most times, but once in a while it still gets
messed up.

PhistucK

unread,
Nov 3, 2010, 9:32:03 AM11/3/10
to atm0s, Chromium Apps
I believe the automatic scrolling is triggered after the onload event fires. Instead of (or in addition to) putting that code into $(window).scroll, try to put that code into the onload handler.

PhistucK

atm0s

unread,
Nov 3, 2010, 9:43:31 AM11/3/10
to Chromium Apps
The code I posted above, is executed inside the onload handler, If I
do the same as with Firefox [ .isFF() ] it does not work.

On 3 nov, 14:32, PhistucK <phist...@gmail.com> wrote:
> I believe the automatic scrolling is triggered after the onload event fires.
> Instead of (or in addition to) putting that code into $(window).scroll, try
> to put that code into the onload handler.
>
> ☆*PhistucK*
Reply all
Reply to author
Forward
0 new messages