Let's say I have example.com/fr/article123 (in french). If the browser-language is not french, I do a redirection to example.com/article123 (in english) with:
<script>
setTimeout(function() { location.href = "example.com/article123" }, 100);
</script>
I know that nowadays search engine crawlers execute JavaScript up to a few seconds.
Question: as of 2021, will example.com/fr/article123 be indexed by GoogleBot on its own, or be considered a 302-redirection of example.com/article123 and therefore not be indexed?
If it is the latter, does this mean that nowadays "automatic redirection to browser language", even when done carefully (see note after), either by PHP or JavaScript, is totally obsolete? Is there no way to do it anymore, if we want to be search-engine-friendly?
Notes:
I only do this under certain conditions: only once with cookies (an english-language user may want to visit the french website after all, so I only try to redirect them once), only if cookies are accepted by browser, etc. I added these conditions carefully, and my tests show it's usually good for user experience.
I first did the redirection with PHP header('Location: ...'); but then I noticed That GoogleSearchConsole and AhrefsSiteAuditTool considered that example.com/fr/article123 is a 302 redirection and therefore not indexed, and that example.com/article123 is its canonical URL (bypassing my <link rel="canonical" href="example.com/fr/article123">), conclusion: it's bad. More info about the PHP solution here: Search engine crawlers get redirected to English pages (and thus avoid other languages' pages) with a multilingual website.