Hi,
I have done some small testing with Fusion 360 javascripts API and it looks very promising. Now I'd like to start a bit larger export project and I could really use a debugger to complete that project.
When the script is launced for debugging, script will run but the debugger will never get started. I created a small test script that shows a messagebox indicating that adsk.debug flag is set to true.
I am currenctly using FireFox (latest) and IE 11. Should I install some other browser or javascript debugging tool to get the actual debugger launched?
Yours,
Lauri
There should be no requirements to install any specific browser for JavaScript debugging. On Windows (which I assume you are because of the IE reference), the Chromium Embedded Framework browser component we use to host the script will serve up Developer Tools web page, and launch that page in the current application associated to open the 'html' file extension. So the only requirement should be having any installed web browser with this association, and a firewall that does not block localhost port 1234 (the default port used for the debug server). The Developer Tools web page used is pretty much the same as the one used in the Chrome web browser, so familiarity with or documentation of Chrome's Developer Tools would apply. Trying this with Chrome installed wouldn't be a bad thing to try, but having Chrome installed should definitely not be a requirement.
One problem that can occur is that the debugger is displayed, but the script does not break, but continues to run. This is often caused by the debugger not coming up in time before the script runs and hits the 'debugger' line. There is currently just a fixed timer after attempting to launch the debug browser and resuming the script. On Windows this delay is three seconds by default. If the debug browser page does not initialize in time (e.g. the browser process is 'cold', or a slow or very busy machine) the script will resume and the 'debugger' line will be a no-op and the script will run as if no debugger was attached. You can set the NEUTRON_JAVASCRIPT_DELAY environment variable with an integer number to override the default number of seconds for this dealy. You can bump up this delay time if the debug browser is coming up but it does not break into your script.
But if the debug browser is not coming up at all, I have not seend that before. You can check if there is any access restrictions on the AdCefWebBrowser.exe process, or if there is a block on this application opening a port, or if there is a conflict with another application using port #1234. If necessary, you can set a NEUTRON_CHROME_DEBUGGING_PORT environment variable override the port number used for the debugging server.
Kris
Thanks for helpful reply. And yes, I am using Windows 7.
I did some experiments with IE 11, by connection directly to localhost port 1234. I actually got the dashboard up but it failed with a script error.
SCRIPT438: Object doesn't support property or method 'remove' File: inspector.js, Line: 5589, Column: 253
Using IE11 for debugging seemed more or less dead end. So I ran same tests with Firefox and the results were similar (Script errors).
So I installed Chrome browser.
Now debugging Fusion 360 scripts works fine. And Fusion 360 will launch Chrome even when it is not set as a default browser. Whether or not this is an intentional behavior, it is actually a good one as debugging Fusion 360 scripts don’t currently work with other browsers (It might work with some other WebKit based browser).
Lauri
@KrisKaplan Where can I find more information on all these env variables NEUTRON_JAVASCRIPT_DELAY NEUTRON_CHROME_DEBUGGING_PORT NEUTRON_CHROME_DEVTOOLS and others.
You was talking about this debug port. Is there any chance I can debug it from outside Fusion? Like with JetBrains plugin/Intellij pair (https://chrome.google.com/webstore/detail/jetbrains-ide-support/hmhgeddbohgjknpmjagkdomcpobmllji) ?
Or maybe I can open this .html file (that goes with .js file) just from my chrome window?
These environment variables are not formally documented anywhere as they should normally not be needed.
NEUTRON_JAVASCRIPT_DELAY
When the debugger is started on a JavaScript script, the debugger (devtools in a visible web browser) is launched. The script is paused to wait for the external debugger to attach to the host before continuing the script. The default delay on Windows is 3s, and on Mac is 1s (Windows is longer because the browser is hosted in an external process, so there is more IPC overhead). This variable, set with an integer number of seconds, lets you change this pause time. Valid values are any integer from 0 to 60. If this value is too short, the debugger may not yet be attached before the script is resumed, so your script will run without debugging (but the debugger should attach afterwards, and you can re-run it from the console or Fusion or query any variables that were set from the initial run). If this value is set too big, you'll just be waiting too long for the script run after the debugger comes up.
NEUTRON_CHROME_DEBUGGING_PORT
This just sets the port number that Chromium will use to communicate with the debugger (Windows only). The default port number used is 1234. It can be set to any integer valid port number. The only reason to ever set this would be if the default port number is in conflict with some other application, or policy restriction on your system.
NEUTRON_CHROME_DEVTOOLS
This should never be set. If it is set (to any value) it will actually disable some functionality in Fusion (such as being able to invoke Fusion from A360). It was only originally suggested because at one point (back in the initial preview release of the JavaScript API) it was used to enable the JavaScript debugger (but now it is always enabled).
I don't know enough about JetBrains, but you would only be able to use it if you are able to connect it to the Chromium devtools debugging port. There would be no option to invoke it automatically that I'm aware of (unless you substituted a proxy process for Chrome somehow). You cannot run a Fusion script in a standalone browser, or the interpreter used by an IDE like JetBrains, because the interpreter that runs our script needs to be hooked with IPC callbacks into Fusion code, and a standalone browser or interpreter would not have this.
Kris
Thank you, this answers some of my questions very well.
NEUTRON_CHROME_DEVTOOLS
So, as I understood, from what you said and trying to set this flag on, there is no way on MAC to start not the safari web inspector, but actual chrome developer tools?
if you are able to connect it to the Chromium devtools debugging port.
I believe JetBrains plugin does exactly that. I will try this out. Having NEUTRON_JAVASCRIPT_DELAY now I can delay and wait for my debugger to connect. The only question still there is - when you talk about "Chromium devtools debugging port" do you mean it works the same on Mac and Win? Because as I said I see some Safari Web Inspector not chrome developer tools.
Correct. On Windows we use a Chromium Embedded Framework based web browser to host the scripts, and on the Mac we use the WebKit framework to host the scripts. That means that Chrome devtools is only used when debugging scripts on Windows, and the the Safari WebInspector is used when debugging scripts on the Mac. Likewise, the Chromium debug port number is a Windows only setting (because it is Chromium specific). I am not aware of any way that you could hook the WebKit's launching of the WebInspector and redirect it on the Mac.
Kris
@KrisKaplan Can you tell me full URL/path to this page / debug session? As you said on windows Fusion starts up separate process (which is chrome/chromium) and as I see on this screenshot there is some specific url used to connect to the debugger. In my IDE I need to specify this path myself.
...
I set this delay to 10 sec. Now when I press "debug" button Safari Web Inspector opens right away and waits for 10 seconds and then opens up my script with debug focused. I am not sure if on MAC this 1234 port thing even work at all? localhost:1234 seems to be not responding in any way.
I see now. Looks like I won't be able to connect from external process in anyway =( thank you.
Don't you mind if I put a list of bugs I've found so far? Some of them are minor, but other are real blockers and I can't see how anyone can do development with JS debugger at all.
I've posted one or two of them months ago here. Now I found more. Not sure, maybe it's better to make separate post on this. You may help me out with this.
Debugger related bugs are probably Mac specific. API ones I assume are common.
var button = commandDefinitions.addButtonDefinition('SaveFacesAsDXFDef', 'blah', 'blah'); ui.allToolbarPanels.itemById('InspectPanel').controls.addCommand(button, 'SaveFacesAsDXFControlId');
// Now I would hope I can find this command by doing this:
ui.allToolbarPanels.itemById('InspectPanel').controls.itemById('SaveFacesAsDXFControlId');
// But it's false. For some reason control stored in this collection with id == SaveFacesAsDXFDef
ui.allToolbarPanels.itemById('InspectPanel').controls.itemById('SaveFacesAsDXFDef');
Here's some information about some of the issues you listed.