Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Magnet link doesn't start torrent download #5981

Closed
srirambv opened this issue Dec 2, 2016 · 38 comments
Closed

Magnet link doesn't start torrent download #5981

srirambv opened this issue Dec 2, 2016 · 38 comments

Comments

@srirambv
Copy link
Collaborator

srirambv commented Dec 2, 2016

Did you search for similar issues before submitting this one?
Yes

Describe the issue you encountered:
Magnet link doesn't start torrent download

Expected behavior:
Should load the torrent viewer and start downloading

@bbondy
Copy link
Member

bbondy commented Dec 5, 2016

@dcposch if you still have cycles available it'd be helpful if you could take a look on the chromium54 branch.

@dcposch
Copy link
Contributor

dcposch commented Dec 5, 2016

@bbondy sure, checking it out

@dcposch
Copy link
Contributor

dcposch commented Dec 7, 2016

Just reproduced the error:

Uncaught SyntaxError: Identifier 'webtorrentEntryPage' has already been declared at webtorrent.js:11

Here's webtorrent.js on the Chromium54 branch:

  let webtorrentEntryPage = 'gen/webtorrentPage.entry.js'

  var queryString = window.location.search
  var portMatch = queryString && queryString.match(/devServerPort=([0-9]+)/)
  var devServerPort
  if (portMatch) {
    devServerPort = portMatch[1]
  }

  let webtorrentEntryPage = 'gen/webtorrentPage.entry.js'
  // [...]

Looks like this commit duplicates webtorrentEntryPage: eb19c30

It's on chromium54 and a few other branches, but not on master.

@dcposch
Copy link
Contributor

dcposch commented Dec 7, 2016

@bridiver

@bridiver
Copy link
Collaborator

bridiver commented Dec 7, 2016

looks like a rebase issue. The webtorrent.js file shouldn't exist anymore

@bridiver
Copy link
Collaborator

bridiver commented Dec 7, 2016

had to sort some things out in master and I'll update the changes for 54

@dcposch
Copy link
Contributor

dcposch commented Dec 9, 2016

@bbondy @bridiver LMK if there's anything you'd like me to do.

Right now, Torrent Viewer doesn't work on the chromium54 branch. I just checked out chromium54 and tried reverting eb19c30, and that fixes the duplicate let statement, but there's a different error because it looks like chrome.ipc is gone? Works on master.

@dcposch
Copy link
Contributor

dcposch commented Dec 9, 2016

Aha, looks like it's called chrome.ipcRenderer now. Changing to use chrome.ipcRenderer doesn't fix it, though

@ayumi
Copy link
Contributor

ayumi commented Dec 16, 2016

@dcposch I get a CSP error when opening this magnet link in Brave 0.13.0 pre4:

screen shot 2016-12-16 at 11 37 37

@srirambv
Copy link
Collaborator Author

Doesn't load the Torrent viewer interface on Windows x64 (0.13.0 Preview 4)
webtorrent

@bridiver bridiver self-assigned this Dec 20, 2016
bridiver added a commit that referenced this issue Dec 20, 2016
partial fix for #5981
links still don't open directly
auditors @bbondy
@bridiver bridiver removed their assignment Dec 20, 2016
cezaraugusto pushed a commit that referenced this issue Dec 20, 2016
partial fix for #5981
links still don't open directly
auditors @bbondy
@bridiver
Copy link
Collaborator

bridiver commented Dec 21, 2016

the urls work with "open in new tab" or ctrl/cmd-click now, but do nothing if you just click on them

@srirambv
Copy link
Collaborator Author

Doesn't work even with "open in new tab". Here's the screen grab
webtorrent1

image

@jonathansampson
Copy link
Collaborator

I see the same thing as @srirambv.

@bridiver
Copy link
Collaborator

reverting eb19c30 is definitely not the right thing to do. The original code incorrectly bypassed the webpack dev server and the csp issues should be resolved in extensions.js

@dcposch
Copy link
Contributor

dcposch commented Dec 28, 2016

@bridiver sure, but eb19c30 doesn't actually run at all due to the syntax error (duplicate let).

not sure how that got merged.

running without the webpack dev server means you have to run npm run webpack after changes to the torrent extension--i don't think it affects the production build. i can try to get the Torrent Viewer working with the dev server later today to make future development faster.

what are the remaining CSP issues?

cc @feross

@bridiver
Copy link
Collaborator

actually eb19c30 was already replaced by other code to handle the dev server and that file doesn't even exist anymore

@bridiver
Copy link
Collaborator

there are a lot of comments on this thread that are no longer relevant so I'm not sure what the outstanding issues are, but the code from eb19c30 is definitely not part of the problem because that file was removed a while ago and the webpack dev server is handled in filtering.js

@dcposch
Copy link
Contributor

dcposch commented Dec 28, 2016

i'm building brave now to try out:

  • clicking a magnet link
  • pasting a magnet link into the URL bar
  • checking for CSP errrors

is master the right branch to be on?

@bridiver
Copy link
Collaborator

bridiver commented Dec 28, 2016

yep, everything from chromium54 has been merged into master and app/extensions/torrent/js/webtorrent.js doesn't exist there. I'm pretty sure that change was already superseded by the filtering change before it was even merged into master.

@bbondy
Copy link
Member

bbondy commented Dec 28, 2016

I don't think the webtorrent filtering code is seeing the magnet protocol URLs at all

@bridiver
Copy link
Collaborator

bridiver commented Dec 28, 2016 via email

@srirambv
Copy link
Collaborator Author

srirambv commented Jan 4, 2017

Seeing this error on 0.13.0 Preview 7

image

@bridiver
Copy link
Collaborator

bridiver commented Jan 4, 2017

why is the page trying to connect to example.com? The only reference I see to that is in a comment

@srirambv
Copy link
Collaborator Author

srirambv commented Jan 4, 2017

image

@feross
Copy link
Contributor

feross commented Jan 11, 2017

Looks like example.com is coming from stream-http's capability detection code. It doesn't actually make an http request. Just calls xhr.open() without xhr.send(). But it looks like that still violates the CSP.

@jhiesey - is there any way to remove example.com from that code, since it could potentially violate the webpage's CSP?

feross added a commit to jhiesey/stream-http that referenced this issue Jan 11, 2017
@feross
Copy link
Contributor

feross commented Jan 11, 2017

Working on a PR to stream-http. Can someone tell me the proper branch to test this on? @bridiver: is master still the right place to test?

@bsclifton
Copy link
Member

@feross master is looking pretty good and is what you should branch from! 😄 if you haven't recently, please remove node_modules and re-npm install

You can tag me as a reviewer (I'd love to try this functionality out; I haven't tried it yet actually)

@feross
Copy link
Contributor

feross commented Jan 11, 2017

Sounds good! 👍

Right now, it looks to me like the torrent viewer code isn't even being triggered when clicking on a magnet link. This must have broken at some point and no one noticed. 😐

@bridiver
Copy link
Collaborator

@feross that is a known issue in 54

@feross
Copy link
Contributor

feross commented Jan 11, 2017

PR to stream-http here: jhiesey/stream-http#65

Haven't confirmed this fixes the CSP issue since I haven't gotten the torrent viewer to run on master yet.

@bridiver Is there an issue for that?

@bridiver
Copy link
Collaborator

@feross isn't this the issue?

@feross
Copy link
Contributor

feross commented Jan 11, 2017

@bridiver It looks like updateWebview in frame.js never gets called when a magnet link is clicked.

That used to get called in the past, and in there we detect it's a magnet: url and load the torrent viewer. Any ideas what's preventing that from getting called for magnet: links now?

@bridiver
Copy link
Collaborator

the redirect is handled here https://github.com/brave/browser-laptop/blob/master/app/browser/webtorrent.js#L37 but that never gets hit because the navigation is completely ignored and I'm not sure why yet

@feross
Copy link
Contributor

feross commented Jan 11, 2017

Unlike normal web requests, the magnet link clicks are getting lost here:

if (e.isMainFrame && !e.isErrorPage && !e.isFrameSrcDoc) {
because e.isMainFrame is false for some reason. Any ideas?

@feross
Copy link
Contributor

feross commented Jan 13, 2017

Okay, the CSP bug fix was just merged and released in stream-http. There should be no more requests to example.com. Now, the remaining issue is to fix the breakage that happened when the chromium54 branch was merged.

@bridiver @bbondy Any ideas why e.isMainFrame is false for clicks on magnet: links but not for normal links. That is causing our handler not to run. See my previous comment.

bbondy added a commit to brave/muon that referenced this issue Jan 16, 2017
It was erroring with:

```
_stream_writable.js
var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate :
```

because our webpack config sets process to false and the process object
we provide doesn't have a version property until now.

processNextTick;

Related to brave/browser-laptop#5981
@bbondy
Copy link
Member

bbondy commented Jan 16, 2017

I'll take a look next, I was trying today but this was blocking me, fixed now:
brave/muon@a1c7592

@bbondy
Copy link
Member

bbondy commented Jan 16, 2017

@feross by the way the torrent file downloads ok, but when I try to play it, in this case an MP3 from here:
magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=udp%3A%2F%2Fexodus.desync.com%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4

It errors with this:

screenshot 2017-01-15 21 05 32

@bbondy
Copy link
Member

bbondy commented Jan 18, 2017

I got this working even for links inside pages, it'll be in the next release. I ended up removing the filtering code and doing it through the same API as navigator.registerProtocolHandler uses.
Beyond that I had to adjust media-src to accept anything from localhost.

It'll be available in the next preview build (0.13.0-preview10)

QA
Click on any of the magnet links from https://codepen.io/ferossity/full/qaezaB/
Torrent viewer should be loaded
Download should start

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants