views:

914

answers:

6

I am developing a web application. I would like to extend my error messages (and their backtraces) so that I can click on the mentioned file, and have it opened automatically in my PHP IDE.

I would like to make this a easy-to-activate feature so that whoever works on the web application, can easily map the error message to point to their local copy of the site, and open their IDE.

What - short of developing a custom FF extension - is the simplest way you can think of to execute a local command (a batch file that calls the IDE) on click in Firefox on Windows(7)? I have looked for extensions but had no luck. Maybe using another extension like Firebug or Greasemonkey?

Security is not an issue, as this is supposed to work on the developer's workstation only and I can change my local Firefox's settings.

+2  A: 

There's not a way to do this with javascript. But it looks possible with a firefox addon. Have a look at this.

Ben Shelock
This looks interesting, but I know nothing about XUL and feel unable to figure out how to turn this into something that executes a local file (instead of writing to it). Hints would be very welcome.
Pekka
Writing an extension is not that difficult. Have a google search for it, read some tutorials and then search for "execute local file firefox extenson".
Marius
point taken. I may return to this but will try the protocol approach (see below) first.
Pekka
+1  A: 

I think that the closest you can get to this, is by having the configuration of the web browser associate a particular mime type with a given "helper application" (here the IDE program), and to have the HTTP server return such a file.

Otherwise, security concerns dictate that browser would not run any "abritrary" program/logic on the client.

mjv
Associating files with the IDE wouldn't help because the file the IDE is supposed to open is the local copy. One could - I didn't think fo this - of course generate .bat files on the PHP side that contain the instructions to open the IDE with the local copy of the file. But due to the tremendous security hole that would open I wouldn't feel comfortable using this in the long term.
Pekka
Alternatively, you could register a protocol handler (as other applications like iTunes and Skype do) that would be handled by your IDE.
0xA3
A: 

I don't know which IDE you're using, but in for example Eclipse you can also use the built-in webbrowser to test your webapp and the exceptions/traces in the Eclipse console log already have links to the source code in question. Easy as that. See if your IDE provides something similar.

BalusC
I use phpEd and need this for remote tests in an environment where I can't use the debugger. Plus, I would like to stay as IDE independent as possible with this.
Pekka
+1  A: 

Pekka,

After reading the thread so far, it seems that you want to build an application that somehow authenticates with the server--i.e.: the "average user" wouldn't have access to it. If this were the case, then delivering it through the browser is an impossibility without writing a custom extension.

Running authentication through GreaseMonkey is difficult, but once the client is authenticated, there is no real way to "run" the trace.

If the server generates a batch file or some kind of instruction set (script, shortcut, etc.), you can simply configure the browser (or have the local instance of your app configure the browser) to run the file. The problem here is that you have no way to automatically authenticate!

The only other way I can imagine that you could get this to work is via a Java applet, which would only be cumbersome and require Java to initialize every time you wanted to import a trace.

The problem you have is that the browser is inherently secure. It's designed to protect the computer from malware, rogue websites, etc etc., and so without developing a custom extension for the browser, there's no way to make the hop to any applications that run in tandem with the browser.

So on that note, I'll suggest that you reconsider writing a Firefox XUL extension as mentioned above. You'll probably need to implement some XPCOM code to make it work, too. Here are some resources that will help get you started:

https://developer.mozilla.org/en/xpcom

https://developer.mozilla.org/En/XUL

http://ted.mielczarek.org/code/mozilla/extensiondev/

https://developer.mozilla.org/en/XUL%5FTutorial/Introduction

mattbasta
Thanks for the expansive answer and the links. Authentication is not the #1 issue, as the error handler in my framework does that already (the rule is "show a generic error message to users, and specific details only if user is logged in as administrator or verbose mode is turned on"). So, for me, being able to somehow turn off *all* security for a certain URL in my local firefox would be the perfect solution. The PHP site could then send me links that point to file://C://development/.... or something. If that doesn't work out though, I will take a look at writing an extension.
Pekka
+1  A: 

You can add a new protocol (like "edit://") to windows (http://msdn.microsoft.com/en-us/library/aa767914%28VS.85%29.aspx) and write a small handler program that picks a filename from the "edit://" url and passes that file to the editor. This way i taught windows to understand txmt links (http://blog.macromates.com/2007/the-textmate-url-scheme/) in the way my mac does.

stereofrog
Funny, I saw a snippet suggesting this but it didn't work straight away and I thought maybe it was limited to a certain OS. I will give this another try. This would be great because it would be browser independent and with very little security implications if done right.
Pekka
+2  A: 

http://mozex.mozdev.org/

MozEX is an extension which allows the user to use external programs for these actions:

* edit content of textareas (possibly utilizing a spell-checker, color syntax etc.)
* view page source
* handle mailto, news, telnet and FTP links
* download files
* ... and many more :)

The universal handler lets you enter a list of protocol schemes, e.g., "abc://,def://" and a command to handle them. So you just have your application generate a url that begins with your chosen (made up) protocol, and mozex will intercept a click on the url and send the url to your chosen command as a paramater.

I think this is exactly what you want.

Winston Smith