webtorrent/webtorrent

2.0.5 fails with "TypeError: Failed to execute 'decode' on 'TextDecoder'"

LostBeard opened this issue · 3 comments

What version of this package are you using?
2.0.5 (latest in dist folder as of time of this bug filing)

What operating system, Node.js, and npm version?
Chrome browser

What happened?

var client = new WebTorrent();
client.on('error', console.log);
client.add('magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent', (t)=>{ window._torrent = t; console.log('fired'); })

Gets this error:

TypeError: Failed to execute 'decode' on 'TextDecoder': The provided value is not of type '(ArrayBuffer or ArrayBufferView)'.
    at p (webtorrent-2.0.5.min.js:1:196518)
    at webtorrent-2.0.5.min.js:1:206809
    at Array.map (<anonymous>)
    at webtorrent-2.0.5.min.js:1:206793
    at Array.map (<anonymous>)
    at webtorrent-2.0.5.min.js:1:206726
    at async P (webtorrent-2.0.5.min.js:1:205425)
    at async lt._onMetadata (webtorrent-2.0.5.min.js:1:252121)

What did you expect to happen?
I expected the client.add() callback to fire.

Are you willing to submit a pull request to fix this bug?
It is simple enough for anyone to reproduce.

Working with latest from https://cdn.jsdelivr.net/npm/webtorrent@latest/webtorrent.min.js

... which turns out to be 1.9.7.

Below example using version 2.0.5 from the dist folder gives the error stated in the original post.

<html>
<head>
</head>
<body>
    <script type="module">
        import WebTorrent from './webtorrent.min.js'
        console.log('version:', WebTorrent.VERSION);  // version: 2.0.5
        let client = new WebTorrent();
        client.on('error', (err) => {
            console.log(err);
        });
        client.add('magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent', (t) => { window._torrent = t; console.log('fired'); })
    </script>
</body>
</html>

I used npm to install webtorrent to a temp nodejs project and took the webtorrent.min.js out of there which is version 2.0.15. That version works with my example.