'html5 validation api gives an empty array of messages if a markup is wrong

Trying to validate my html5 markup by clicking on a button and using the w3c validator. The code source is from here.

so my code is like this:

$('.btnw3').on('click', async function(){
    valid()
  .then(data => {
    console.clear();
    console.log(data); // Console was cleared - {messages: Array(0)}
        const error = data.messages.filter(msg => msg.type === 'error');
const warning = data.messages.filter(msg => msg.type === 'info' && msg?.subType === 'warning');

if (warning.length) {
  console.group(`%c${warning.length} validation warnings`, "background-color:#FFFBE5;padding:1px 4px");
  warning.forEach(msg => {
    console.groupCollapsed(`%c${msg.message} (line: ${msg.lastLine})`, "background-color:#FFFBE5");
    console.table(msg)
    console.groupEnd();
  })
  console.groupEnd();
}
if (error.length) {
  console.group(`%c${error.length} validation errors`, "background-color:#D93025;color:#FFF;padding:1px 4px");
  error.forEach(msg => {
    console.groupCollapsed(`%c${msg.message} (line: ${msg.lastLine})`, "color:#D93025");
    console.table(msg)
    console.groupEnd();
  })
  console.groupEnd();  // empty output
}
  })

});

so I intentionally make my markup wrong - write </divx> instead of </div> - for example

problem - I'm getting an empty array of messages on (console.log(data)) line

the same happens if I write this code as a snippet in chrome dev tools

if I copy my markup source and paste it on https://validator.w3.org/nu/#textarea - I'm getting the expecting errors.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source