adobe-research / theseus

A pretty darn cool JavaScript debugger for Brackets
Other
1.34k stars 69 forks source link

Theseus will not debug in Chrome when using Proxy Mode settings #12

Closed Revlin closed 11 years ago

Revlin commented 11 years ago

Tom commented in a previously closed issue:

I just realized that I misunderstood what the project URL setting did. I'll test Theseus with it more to see if I can make it less confusing

When setting the project in Brackets to serve files from a specified url, Theseus does not report debug info. This is true whether the File menu selection is set to 'Mode: Serve files from disk' or 'Mode: Proxy to localhost:3000'. Even if the files are being served from the domain localhost and port 3000, Theseus is not active in Brackets.

This effectively restricts Theseus use in Chrome to the Brackets internal http server.

alltom commented 11 years ago

If you leave the Project Base URL empty and use Theseus' Proxy mode, then you can use whatever server you want (so long as it listens on localhost:3000 (for now)). Can you try that?

Revlin commented 11 years ago

If you leave the project base url empty, node starts it's own internal server and listens on a random port when serving files to chrome (usually something like 127.0.0.1:5####). At least that's how the windows version works, so without the project base url settings regardless of whether 'Mode: Serve files from disk' or 'Mode: Proxy to locahost:3000' is selected, Brackets will not serve files at localhost:3000 and Chrome will not request files at localhost:3000. In other words, 'Mode: Proxy...' does not alter the base url or port number in any way when launching to Chrome. Thus, since 'Mode: Proxy...' seems to cause Theseus to expect localhost:3000 to be listening, it will not function in this mode because Brackets is not serving from localhost:3000

Also, given the above situation, with 'Mode: Proxy...' selected (and no project base url set), launching some of my projects causes the following error msg in chrome:

An error has occurred (have you started a server on port 3000?): {"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect"}

This happens when my external http server is not running. As soon as I start it up with port 3000, this error msg goes away, confirming I suppose that Theseus is trying to connect to 3000 (still no debug msg though, because Brackets is using a different server, listening on a different port).

alltom commented 11 years ago

If you do not have a Base URL configured and Theseus is in static file mode:

  1. You click the lightning bolt.
  2. Brackets starts a server on a random port, serving files directly from disk (filtered with Theseus).
  3. Brackets opens a Chrome window with the URL for that random port.

If you do not have a Base URL configured and Theseus is in Proxy mode:

  1. You click the lightning bolt.
  2. Brackets starts a server on a random port. Requests to that server are proxied to http://localhost:3000/ and the responses are filtered with Theseus. If there is no server listening at http://localhost:3000/, Theseus returns "An error has occurred (have you started a server on port 3000?)" instead. You are expected to run a server by running rails server or node app.js or whatever your server is for the project.
  3. Brackets opens a Chrome window with the URL for that random port (not 3000).

It might also help to explain the "experimental" flag on the Proxy menu item. Proxy mode is built on top of hacks that just happen to work some of the time. If both of the following conditions are true, then Theseus will work in Proxy mode:

  1. Your server gives all the JavaScript files URLs that make it obvious which files they correspond to on disk. For example, the URL /x.js exists in your project at exactly /x.js or /public/x.js or /app/assets/javascripts/x.js. It won't work if x.js exists at any other path relative to your project.
  2. The JavaScript files don't get processed at all by your project's server, so their contents exactly match what is on disk.

Otherwise, Theseus will stare at you dumbly and not show any debugging information for any of your files. Internally, every time you open a file in Brackets, Theseus asks, "Does this look like it corresponds to any of the JavaScript URLs that are currently open on the page?" and when the answer is yes, it shows debugging info.

Does these explanations help you figure out what's going wrong in your case? If the problem is the URL<->filename mapping (which would be my guess), I'd love to know a little more about your project setup so I can improve it since it's inherently fragile.

Revlin commented 11 years ago

Ok, scenario two ("If you do not have a Base URL configured and Theseus is in Proxy mode") works... sometimes. All things being the same, in Brackets sprint 26, sometimes my web page shows up in Chrome and then Theseus debug markup lands on my js files in Brackets, but sometimes no debug output, even on the same file in the same project. Maybe this goes back to the "race" condition you mentioned in an earlier issue discussion? Maybe it has to do with the randomly chosen port (some work in the proxy, some don't)?

I'm not sure, but basically I just followed your sequence twice, with the same project open in Brackets, the same server running at localhost:3000, and the first time it failed to debug (also my page took a loooong time to show up in Chrome), and the second time it started showing debug info (and the page initialized in Chrome much faster). Maybe this is a bug in Brackets or the Chrome plug-in/initializer?

So is the purpose of the Proxy mode to allow a developer to choose which server (kind) the project is running on and therefore enable features that the Brackets internal server does not provide (like CGI)? Sorry, to go off topic here, but I'm curious.

I'm just upgrading to sprint 27, so if you don't hear from me, everything works great :)

thx, Rev

alltom commented 11 years ago

Large JavaScript files like jquery.js take a really long time to process the first time, but the result is cached. I wouldn't be surprised if something in Brackets times out before that process finishes, preventing the connection from completely establishing. You can put /*theseus instrument: false */ in large files, or add theseus=no to their URL parameters (like <script src="script.js?theseus=no" />) to prevent them from being instrumented.

And yeah, Proxy mode exists because most new web sites have server-generated files and it doesn't make sense to build every server into Theseus. :)

If you upgrade to Sprint 27, get Theseus 0.3.1 (released today). Sprint 27 broke Theseus 0.3.0.

Revlin commented 11 years ago

I've upgraded Bracket to Sprint 27 and Thesesus to 0.3.1 and following the directions listed in comment 4 of this issue, all is working as expected. I have some rare times when Brackets failes to launch the Chrome preview, but this now seems unrelated to Theseus. I hope at some point I will be able to set an arbitrary host and port to serve project files from as Theseus debugs the Chrome instance, but that's more of a feature request. Thanks, Tom!