0

The initial URL is

https://robertbarakett.com/products/the-barakett-t-hoodie?option1=Blue+night&option2=S

I traced the HTTP requests. It only does 1 redirect: from

https://robertbarakett.com/products/the-barakett-t-hoodie?option1=Blue+night&option2=S 

to

https://robertbarakett.com/products/the-barakett-hoodie-black?option1=Blue%20night&option2=S.

However, the final URL in the address bar is

https://robertbarakett.com/products/the-barakett-hoodie-black?variant=31966791729263.

I read about changing URL without reloading page:

  1. How do I modify the URL without reloading the page?
  2. Appending parameter to URL without refresh

Since there is no navigation history after loading the web page, it rules out window.history.pushState. Maybe it uses window.history.replaceState? I did a search in the page's source code, didn't find any use of replaceState. So how to verify whether it uses replaceState or other techniques?

j08691
  • 190,436
  • 28
  • 232
  • 252
an0
  • 16,371
  • 11
  • 78
  • 132

1 Answers1

1

Is using window.history.replaceState

In: https://cdn.shopify.com/s/files/1/0061/4134/5903/t/13/assets/theme.js?v=13437044988013674143

Its has:

_updateHistoryState: function(variant) {
   if (!history.replaceState || !variant) {
     return;
   }
  
   var newurl = window.location.protocol + '//' + window.location.host + window.location.pathname + '?variant=' + variant.id;
   window.history.replaceState({path: newurl}, '', newurl);
},

Is the only place in the source which assigns ?variant

Found by downloading site (right-click save-as), then doing a search for ?variant

Lawrence Cherone
  • 41,907
  • 7
  • 51
  • 92
  • Amazing! I searched `variant` myself and found several reference. But how could you trace it down to that specific JS file? There are quite some JS files. – an0 Nov 13 '20 at 18:08
  • np, is lots of `variant`, but only one `?variant`. I saved the page, opened in vs-code then did a search Ctrl-Shift-F, was the only file to show up.. It would take too long to look manually through every file or request response – Lawrence Cherone Nov 13 '20 at 18:12
  • Just realized what you mean by "right-click save-as", that does the trick! – an0 Nov 13 '20 at 19:33