Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebTorrent browser version does not work with Web Streams Polyfill #1367

Closed
fijiwebdesign opened this issue May 1, 2018 · 2 comments
Closed

WebTorrent browser version does not work with Web Streams Polyfill #1367

fijiwebdesign opened this issue May 1, 2018 · 2 comments
Labels

Comments

@fijiwebdesign
Copy link

@fijiwebdesign fijiwebdesign commented May 1, 2018

What version of WebTorrent?
0.99.3

What operating system and Node.js version?
Mac 10.12.5 (16F73)

What browser and version? (if using WebTorrent in the browser)
Chrome Version 66.0.3359.139 (Official Build) (64-bit)

What did you expect to happen?
Download file

What actually happened?
Error:

Uncaught (in promise) TypeError: Illegal invocation
    at new n.IncomingMessage (webtorrent.min.js:1)
    at t.exports.h._connect (webtorrent.min.js:1)
    at webtorrent.min.js:1

Error context

var d = new WritableStream({
                                write: function(e) {
                                    return new Promise(function(t) {
                                        s._destroyed || (s.push(new o(e)) ? t() : s._resumeFetch = t)
                                    }
                                    )
                                },
                                close: function() {
                                    s._destroyed || s.push(null)
                                },
                                abort: function(e) {
                                    s._destroyed || s.emit("error", e)
                                }
                            });
                            try {
 error -->                               return void n.body.pipeTo(d)
                            } catch (t) {}

Test code:

<script src="https://cdn.jsdelivr.net/npm/web-streams-polyfill@1.3.2/dist/polyfill.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/webtorrent/0.99.3/webtorrent.min.js"></script>

<script>

let webTorrent
document.addEventListener('DOMContentLoaded', () => {
  webTorrent = new WebTorrent()

  const torrentId = 'https://webtorrent.io/torrents/sintel.torrent'

  webTorrent.add(torrentId, torrent => {
    console.log('torrent ready', torrent) 
  })
})

</script>

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented May 10, 2018

This error is coming from within the browserify http shim (aka @jhiesey's stream-http package). I suspect that your Web Streams polyfill is causing that library to crash somehow.

@feross feross added the question label May 10, 2018
@feross feross closed this May 10, 2018
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented May 10, 2018

I just took a look and the polyfill that you're using doesn't appear to be very good. It's blindly overwriting ReadableStream, WritableStream, etc. even if they already exist on window. See: https://github.com/creatorrr/web-streams-polyfill/blob/master/index.es6.js#L20-L21

It shouldn't do that. So even though Chrome already has WritableStream support, this library is overwriting it with a version that doesn't work.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.