Force protocol on url() method in localhost (& Browsersync)?

I have an issue with my development setup.

I want to echo an url in a data-attribute. I then use this url to update the displayed url in the browser :

History.replaceState(null, document.title, url);

It works fine in a prod server and even a regular localhost, I get urls like http://localhost/the-path.

But I’m using browsersync which runs on a :3000 port, and from there I don’t get this “absolutely absolute” url but :

//localhost:3000/the-path

Which messes things up when used as is to modify the browser history. Of course it isn’t that painful to rewrite it afterwards with the correct protocol, but I still wonder if there’s a way to echo it with the protocol in the first place ? :thinking:

I use browsersync locally. How do u have it configured? I use it as a proxy on a local domain (yoursite.dev) rather then viewing the site directly on localhost:3000. might solve your issue.

This is my setup

Sorry for the delay, it was indeed a config issue when setting the proxy ! Back to normal, thanks for the example :wink:

No worries, glad you got sorted.