Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Fusion 360 Javascript debugging

11 REPLIES 11
Reply
Message 1 of 12
lakal3
1467 Views, 11 Replies

Fusion 360 Javascript debugging

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

Tags (1)
11 REPLIES 11
Message 2 of 12
KrisKaplan
in reply to: lakal3

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



Kris Kaplan
Message 3 of 12
lakal3
in reply to: KrisKaplan

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

 

Tags (1)
Message 4 of 12
soswow
in reply to: KrisKaplan

@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?

Message 5 of 12
KrisKaplan
in reply to: soswow

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



Kris Kaplan
Message 6 of 12
soswow
in reply to: KrisKaplan

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.

Message 7 of 12
KrisKaplan
in reply to: soswow

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



Kris Kaplan
Message 8 of 12
soswow
in reply to: soswow

@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.

Message 9 of 12
soswow
in reply to: KrisKaplan

I see now. Looks like I won't be able to connect from external process in anyway =( thank you.

Message 10 of 12
soswow
in reply to: soswow

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.

 

  • Copy paste not working in Web Inspector. When you select stuff in code editor or in console like and try to copy I see how Fusion's "edit" menu lights up, but it doesn't copy anything. Same for pasting. My theory, is that it trys to copy something inside Fusion, and not inspector window.
  • Web Inspector is still under Fusion's UI toolbars. That's really annoying.
  • Related to that: If I am in fullscreen mode and switch from Web Inspector to Fusion itself, I won’t be able to open Web Inspector without resizing Fusion window itself. Web Inspector is hiding behind Fusion windiw. There is no separate running application icon to switch to it.

 

  • When I start debugging session it briefly shows code then switches to the html page and stays there

 

  • Once you opened JS script in debug it won’t grab any changes you made to the script outside - That’s the biggest one. In order to see changes you have to restart Fusion. That's a blocker.
  • Still can’t define variables in web inspector console. It would be really handy and for me it also kinda a blocker.

 

  • This one is more about API itself. I would expect some API where I add new something with an ID (something that I can later find with itemById method) to blow up when I try to add an object with ID already in the collection. 

 

  • I think there is a bug with API. Look at this code:
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');

 

Message 11 of 12
soswow
in reply to: soswow

@Anonymous is there anything I can expect on this thread?

Message 12 of 12
ekinsb
in reply to: soswow

Here's some information about some of the issues you listed.

 

  • Once you've opened a JS script in debug it won't pick up any changes.
    There is another topic that discusses this.  Unforutnately, this is a regression in the web toolkit that we have to wait for Apple to fix.
    http://forums.autodesk.com/t5/api-and-scripts/javascript-script-changes-not-being-picked-up-need-to-...
  • No failure when creating an item with the same ID.
    Do you have a specific example of this?  In the cases where Fusion doesn't allow duplicate names, the API should be failing when you try to use an existing name.  There are some cases in Fusion where it allows duplicate names and the API supports that same.
  • In your code where you're creating and using a buttonDefinition, there were some changes made a couple of updates ago around the UI that fix an underlying issue with how this was done with the API.  The buttonDefinition has an ID, but controls are no longer assigned a unique ID but inherit the ID from the buttonDefinition.  Internally, that's how it has always worked but the API was wrong and has now been corrected.

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report