chrome, опера, firefox, консоль не показывает ошибку? - PullRequest
0 голосов
/ 29 января 2020

Это случилось недавно, я обнаружил, что все мои браузеры, chrome, опера, firefox, консоль больше не выдает ошибку, просто молча остановим сценарий js.

console.log(' undefined variable should show error ', aa, bb)

Раньше консоль отображала ошибку: «aa» не определена, но теперь ничего не отображается на консоли, у меня последняя версия opera v66.0.x, chronm v79.0.x

Редактировать 1/29/2020

Я вроде как нахожу проблему. Если я поставлю

         console.log(' undefined variable should show error ', aa, bb) 

в обычном месте, браузер выдаст:

              Uncaught ReferenceError: aa is not defined

Однако, если я поместил тот же код в поток выборки, даже этот код был реализован, он был запущен в, браузер, консоль НЕ будет отображать никаких сообщений об ошибках, просто прекратите запуск сценария js SILENTLY!

                  // ----- fetch.stream api -----
                  fetch(_url_decoded)
                             // Retrieve its body as ReadableStream
                      .then(response => response.body)
                      .then(rs => {

                                  //console.log('test ', uuuu)


                                  const reader = rs.getReader();

                                  return new ReadableStream({


                                    async start(controller) {




                                            while (true) {


                                                          const { done, value } = await reader.read();

                                                          // When no more data needs to be consumed, break the reading
                                                          if (done) {


                                                                  console.log('test ', uuuu)

Я проверяю регистр на всех последних версиях firefox, chrome, opera, all та же тишина останавливается без вывода какого-либо сообщения об ошибке !!!

  Who can tell me why?

1 Ответ

0 голосов
/ 29 января 2020

Я исправляю проблему, ее сложно объяснить, я не знаю, где проблема.

Это рабочий код : консоль сообщит об ошибке по любой неопределенной переменной

        fetch("https://www.example.org/").then((response) => {
               const reader = response.body.getReader();
                const stream = new ReadableStream({
                    start(controller) {
                            // The following function handles each data chunk
                              function push() {
    // "done" is a Boolean and value a "Uint8Array"
    reader.read().then(({ done, value }) => {
      // Is there no more data to read?
      if (done) {
        // Tell the browser that we have finished sending data
        controller.close();
        return;
      }

      // Get the data and send it to the browser via the controller
      controller.enqueue(value);
      push();
    });
  };

  push();
}
});

  return new Response(stream, { headers: { "Content-Type": "text/html" } });
});

В моем исходном коде есть проблема, консоль не будет сообщать об ошибке на любой неопределенной переменной, просто тихо остановите js engine.

                 fetch(_url_decoded)
                             // Retrieve its body as ReadableStream
                      .then(response => response.body)
                      .then(rs => {

                                  // will catch error at below catch block
                                  // console.log('test ', uuuu)


                                  const reader = rs.getReader();

                                  return new ReadableStream({


                                    async start(controller) {

                                                                // will not show error undefined in console.  
                                                                //console.log('test ', uuuu) 


                                            while (true) {


                                                          const { done, value } = await reader.read();




                                                          // When no more data needs to be consumed, break the reading
                                                          if (done) {

                                                                    break;   // or,  return, depends on, here use while loop, so use break. if it is recursive function "processText()",then use 'return' here.
                                                          }




                                                          // Enqueue the next data chunk into our target stream
                                                          controller.enqueue(value);

                                            } //while




                                            // after 'done' , break the while loop, come here to Close the stream

                                            controller.close();
                                            reader.releaseLock();

                                            return;
                                    } // start




                                  }) // ReadableStream



                    })// then   
                    .catch((error) => {
                      console.error('fetch Error -> :', error);
                    });
...