Google’s John Mueller said another thing that might be important if you have a JavaScript heavy website: Google only process the rel=canonical on the initially fetched, non-rendered version. That means that any canonical tags that are inserted by JavaScript will be ignored by Google.
We (currently) only process the rel=canonical on the initially fetched, non-rendered version.
— John ☆.o(≧▽≦)o.☆ (@JohnMu) 10. Mai 2018
Do not rely on JavaScript
JavaScript should only be used to enhance your web pages. It should not be necessary to display your pages. Further information about this can be found here and here.
Make sure that your web pages work without JavaScript. You can check your website with the website audit tool in SEOprofiler. You can create your free account here: