chrome, opera, firefox, console not show error?

347 views Asked by At

It happen recently, I found all my browser, chrome, opera, firefox, console not show error anymore, just silently stop js script.

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

Before, console, will show error: 'aa' is undefined, but now, nothing show on console, I have latest version opera is v66.0.x, chronm is v79.0.x

Edit 1/29/2020

I kind of find the problem. If I put

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

in the regular place, browser does output:

              Uncaught ReferenceError: aa is not defined

However, if I put the same code in fetch stream, even this code was implemented, was run into, browser, console will NOT show any error message, just stop run js script 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)

I test the case on all latest version of firefox, chrome, opera, all the same silence stop without output any error message!!!

  Who can tell me why?
1

There are 1 answers

0
hoogw On

I fix the problem, it is complicated to explain, I don't know where is problem.

This is working code: console will report error on any undefined variable

        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" } });
});

My original code have problem, console will not report error on any undefined varible, just quietly stop 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);
                    });