Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll position not retained in Firefox, IE #630

Closed
digitalCitizen opened this issue May 20, 2015 · 33 comments · May be fixed by tobybellwood/govstrap#4
Closed

Scroll position not retained in Firefox, IE #630

digitalCitizen opened this issue May 20, 2015 · 33 comments · May be fixed by tobybellwood/govstrap#4

Comments

@digitalCitizen
Copy link

Previous (closed) issue with recent update here: #80

The issue is that after a change in the code, the page refresh causes the scroll location to be set to the top of the page. This happens in Firefox 37.0.2, and in Firefox Developer Edition 40.0a2 (2015-05-19) and IE 11.

In Chrome everything works nicely.

@faergeek
Copy link

Unfortunately, I can't test it in IE11 right now.
@shakyShane can you try to remove forceReload from window.location.reload calls and test it?
It fixes issue for Firefox.

I mean change

window.location.reload(true);

to

window.location.reload();

@Siilwyn
Copy link

Siilwyn commented Jun 12, 2015

Can confirm this also happens on Firefox 38.0 on Ubuntu 14.04.
@faergeek I would be happy to test but can't find the above snippets of code in the source...

@faergeek
Copy link

@Siilwyn
Copy link

Siilwyn commented Jun 14, 2015

I wasn't aware that browser-sync is split up.
Unfortunately removing the forceReload doesn't fix this issue in Firefox 38.0 on Ubuntu 14.04.

@faergeek
Copy link

@Siilwyn, did you run gulp build before testing?

@Siilwyn
Copy link

Siilwyn commented Jun 14, 2015

@faergeek oh I also missed that it was being build with gulp, thanks for bearing with me. That indeed fixed it. Should I open a pull request changing the code to detect Firefox and pass false to the reload function?

@faergeek
Copy link

I think there's no reason to detect Firefox or IE, equally as no reason to pass false there, it is false by default. It's because I think that caching should be disabled for development anyway.
What do you think, @shakyShane?

@shakyShane
Copy link
Contributor

@faergeek - without passing true, many browsers will not send a new request & whilst you may be able to disable caching in your devtools or whatever, how will it affect devices you're also testing on?

@faergeek
Copy link

faergeek commented Jun 15, 2015 via email

@faergeek
Copy link

Another workaround is to disable UA detection when save/restore scroll position from cookies.

@shakyShane
Copy link
Contributor

I've just some testing on Chrome, Firefox, iOS, IE9 etc and all send to still perform the request

Because of this I'm happy to remove the true argument from reloading. Any cache preventing can always be done on a project specific basis, by using headers etc,

@digitalCitizen
Copy link
Author

I must be doing something wrong... If I remove the "true" in the files as specified by @faergeek, the browser (Firefox Developer edition 40.0a2) still pops back to the top after a sync reload. The disable cache setting is turned on in devtools.

@shakyShane
Copy link
Contributor

How are you running Browsersync with the modified script?

@shakyShane
Copy link
Contributor

Hmm, yeah I see the same problem in IE11

@shakyShane
Copy link
Contributor

Wow, just learned about window.name - Seems a perfect candidate for this
https://en.wikipedia.org/wiki/HTTP_cookie#Alternatives_to_cookies

@digitalCitizen
Copy link
Author

@shakyShane: I forced an update to the latest version of browserSync, made the changes in the files, ran gulp build and then started gulp.

@faergeek
Copy link

@shakyShane, window.name is cool, but what if it's already used by app somehow?

@shakyShane
Copy link
Contributor

Can we not just namespace writes to it?

There's a tradeoff for any approach though.

  1. Cookies are sent over the wire with every request - bad
  2. Local storage persists across all open tabs in same browser - bad

@faergeek
Copy link

I don't think we can use namespaces there, it's just a string.

@faergeek
Copy link

I think we can prepend our data to window.name on beforeunload and then remove it after read, but it should be done as early as possible, before any other script on the page.

@shakyShane
Copy link
Contributor

Any examples of frameworks/apps that actually use window.name? I don't think I've ever seen it.

Either way, my thoughts are that we default to it (works great in my tests) but allow users to use the cookie drop instead via an option.

@faergeek
Copy link

@shakyShane
Copy link
Contributor

Please all try 2.7.11

I have tested in all browsers back to IE8 and it's working great now.

I'm aware that using window.name may have an impact re: conflicts with other libs - but I think this is so unlikely that i'm happy to risk it for now & users can opt-out easily if needed.

@digitalCitizen
Copy link
Author

Yes, supersweet. This works for me! Tested in Firefox, Firefox Developer Edition, IE 11.
Thanks :)

@shakyShane
Copy link
Contributor

@digitalCitizen Thanks for reporting

@Siilwyn
Copy link

Siilwyn commented Jun 17, 2015

Really nice! It even seems to work better now, the browser window doesn't flash at the refresh like it did before. @shakyShane thank you!

@shakyShane
Copy link
Contributor

@Siilwyn - Yeah I made a couple of other improvements whilst there :p

Also, if you are pleased with the support we give, you could extend your thanks by voting for us

:)

@benjaminkitt
Copy link

A quick note about a conflict I found:

Protractor uses an Angular feature called Deferred Bootstrap that uses window.name and conflicts with BrowserSync. From the AngularJS Docs:

This feature enables tools like Batarang and test runners to hook into angular's bootstrap process and sneak in more modules into the DI registry which can replace or augment DI services for the purpose of instrumentation or mocking out heavy dependencies.

If window.name contains prefix NG_DEFER_BOOTSTRAP! when angular.bootstrap is called, the bootstrap process will be paused until angular.resumeBootstrap() is called.

If Browsersync overwrites that window.name value before it gets caught by Angular, Angular will not defer its Bootstrap and Protractor will subsequently not be able to find the resumeBootstrap function because it won't exist.

Switching to the cookie drop resolves this issue, but took me a long time to troubleshoot!

@socheon
Copy link

socheon commented Jan 1, 2016

Hi. I am using browser-sync@2.10.1 and Google Chrome (v43.0.2357.130) on Ubuntu. The scroll position, say after using for 5 minutes, starts to jump to another position when reload. When I restart the browser, the problem seems to go away again. Is there a way to check what's wrong? Or something I can run on the browser console, so that I don't have to close all my tabs and restart the browser?

@bjornhanson
Copy link

Is this problem back? I'm testing with several browsers on several platforms, using BroswerSync 2.14.0. When I scroll in Chrome, I see other Chrome, Safari, and Edge windows scroll together, but not Firefox or IE 11. If I scroll in Firefox, I see Firefox and IE 11 windows scroll together.

@digitalCitizen
Copy link
Author

digitalCitizen commented Aug 5, 2016

This issue was not about scroll syncing in different browsers, but about the scroll position popping back to top after a code change/auto refresh.

@MariuszDabrowski
Copy link

Having the same issue, on every refresh the page starts back at the top.

OSX El Capitan
Chrome Version 51.0.2704.103 (64-bit)

@testgit-1
Copy link

Have the same problem.
Firefox 55.0.2 (32-bit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants