MITM Not Receiving MessageChannel on writer.close()

See original GitHub issue

Browser: Chrome Version 80.0.3987.132

Issue: Calling writer.close() on a WritableStreamDefaultWriter results in a TypeError in the mitm (showing up in my web app Chrome console). The full error is: Uncaught TypeError: [StreamSaver] You didn't send a messageChannel at onMessage (mitm.html?version=2.0.0:66). Stepping through the StreamSaver code, it seems like it occurs after this end message gets sent in the StreamSaver.js main file on line 279:

close () {
   if (useBlobFallback) {
     ........
   } else {
     channel.port1.postMessage('end')
   }
 },

Code: Here’s a basic implementation that is resulting in this error message:

fetch("http://localhost:8075")
   .then((resp) => {
      const writer = streamSaver.createWriteStream("test_file.csv").getWriter();
      const reader = resp.body.getReader();
      const pump = () => reader.read()
         .then((res) => {
            if (res.done) {
               writer.close();
            } else {
               writer.write(res.value)
                  .then(pump);
            }
         });
      pump();
   });

The code runs fine in Safari, but I get that console error in Chrome. Other than the console error, the download seems to be working fine in Chrome. Any idea why i’m seeing this? Is it related to using an insecure site for development? Let me know if you need more info - any help you can offer is greatly appreciated.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jimmywartingcommented, Mar 10, 2020

Hmm, not sure what it is. can’t reproduce.

  • localhost is considered secure. so you shouldn’t see any popup.
  • safari don’t use workers/mitm at all cuz it can’t download content generated on the client side, it switches to just download the url behind it and avoiding the hole respondWith (resulting in a 404 error). instead it generates a blob and use a[download] #69
  • the MITM shouldn’t receive any such event - it should just accept a postmessage event, pass it along to the service worker and be done with it. the rest of the communication happens throught MessageChannel.

if the download is doing just fine then maybe you don’t have anything to worry about. it could be that something else is posting messages to any iframe that exist in the DOM tree. you could try putting a breakpoint at the message event at look what the message data look like.

0reactions
antoniolucasnobarcommented, Sep 8, 2022

I have this very same problem on mac using Firefox and Chrome. The download works ok, only this message appears on console after the download is completed. I use this in a Vue.js app.

Here is the code I use to download:

            fetch(this.getApi(),
                {
                    headers: {
                        'Accept': '*/*',
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                    credentials: "include",
                    method: "GET",
                }).then(response => download(response))


// here is the download method:
        download: function ( response ) {
            const streamSaver = window.streamSaver;
            // if you decide to host mitm + sw yourself
            streamSaver.mitm = 'downloadutil.html'

            const fileStream = streamSaver.createWriteStream('relatorio.csv', {});
            return response.body
                .pipeTo(fileStream)
                .then(() => console.info("Sucesso"), (erro) => console.error(erro));
        },
Read more comments on GitHub >

github_iconTop Results From Across the Web

StreamSaver.js
Calling writer.close() on a WritableStreamDefaultWriter results in a TypeError in the mitm (showing up in my web app Chrome console).
Read more >
MessageChannel - Web APIs | MDN
When a message is received back from the IFrame, the onMessage function outputs the message to a paragraph. const channel = new MessageChannel() ......
Read more >
SWAPP: A New Programmable Playground for Web ...
Cannot receive a postMessage. 2 Background and Motivation. In this section, we first provide the background on what is a.
Read more >
Unreachable Peers Communication Scheme in ...
The goal is to implement a decentralized end-to-end communication solution ... So authentication cannot be performed in this way, making MITM attacks more ......
Read more >
ChangeLog-14.3.1 - Index of / - Asterisk.org
ASTERISK-21094 #close Reported by: David Woolley Patches: ... EPIPE was handled in ast_carefulwrite() a few lines above, but not in this function.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found