Back

Deprecated code

What is deprecated code ?

Deprecated code is mainly JavaScript code that uses obsolete browser functions. The browser temporarily maintains these outdated functions (they are API - Access Programming Interface methods) for compatibility reasons but tends to remove or modify them in the near future. 

Why should it be avoided ?

When the browser is updated, the code using these methods may no longer work and thus cause JavaScript errors. The appearance of errors can lead to more or less serious problems depending on the usefulness of the code. The content may be missing, navigation in the site may no longer work, interactions with the different elements of the page may not respond. In other words, your page starts to have bugs that were not present until now.

How to correct deprecated code

When a method provided by the browser is marked as deprecated, it is necessary to intervene in the code in order to change the method for an alternative to ensure future compatibility. If this code comes from the use of a third party module, it is then necessary to update it or to find a more modern alternative.

Deprecated methods appear as a warning in the Chrome browser console. Here is a warning on the presence of an obsolete method whose use will soon change :

speechSynthesis.speak() : speechSynthesis.speak() without user activation is no longer allowed since M71, 
around December 2018. See https://www.chromestatus.com/feature/5687444770914304 for more details