7

I am facing this issue across all browsers. This comes up whenever I try to view my site in Google cache

main.bundle.js:1 ERROR Error: Uncaught (in promise): SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'https://mydomainn.com/' cannot be created in a document with origin 'http://webcache.googleusercontent.com'. The same problem lies with express google. http://webcache.googleusercontent.com/search?q=cache%3Ahttps%3A%2F%2Fexpress.google.com%2Fstores&oq=cache%3Ahttps%3A%2F%2Fexpress.google.com%2Fstores&aqs=chrome..69i57j69i58.3999j0j4&sourceid=chrome&ie=UTF-8.

My base href is /

Adam Young
  • 1,321
  • 4
  • 20
  • 36
  • Possible duplicate of [Angular deployment without server - Error: SecurityError: Failed to execute 'replaceState' on 'History'](https://stackoverflow.com/questions/49365057/angular-deployment-without-server-error-securityerror-failed-to-execute-rep) – Randy Casburn Apr 03 '18 at 05:16
  • hi, did you solve your issue ? – Kevin Vincent May 11 '18 at 22:47

1 Answers1

16

In your routes configuration add

 RouterModule.forRoot(routes, {useHash: true});

In your index.html do this;

 <!-- <base href="/"> -->
 <script>document.write('<base href="' + document.location + '" />');</script>

And then build with --base-href ./ e.g

ng build --prod --base-href ./

source https://github.com/angular/angular/issues/13948

theeGwandaru
  • 400
  • 2
  • 14
  • Sir, you just saved my work day. Can't say if the answer solves the question though, as my issue was of different kind (index.html on a server and all application files on another) – Giulio Prina Ricotti Sep 04 '18 at 08:41
  • I myself was trying to load an application from file system and ended up with this. Glad it was of whatever help it was to you. – theeGwandaru Sep 04 '18 at 09:44
  • Me ajudou muito. Thanks – Ezequiel Tavares May 22 '20 at 05:32
  • @theeGwandaru, Hi, I am facing same issue in react server side rendering with. Can you please check https://stackoverflow.com/questions/63115145/domexception-failed-to-execute-replacestate-on-history-a-history-state-obj It will be great if you could tell what could have caused this issue. – Always_a_learner Jul 29 '20 at 05:09