Jump to content

Putting Breakpoints to scripts loaded via game.load.script


Ludomancer
 Share

Recommended Posts

This is more of a questions really.

Searched a bit around the issues, change-log and this forum but couldn't find an answer for it. I'm loading bunch of scripts dynamically via game.load.script. As expected I can't put brekapoints and debug those scripts.

I'm aware of sourceURL solution, but couldn't get it working.

Is there any way to put breakpoints and debug dynamically loaded scripts?

Any help or information would be appreciated.

Link to comment
Share on other sites

Use the debugger statement. Wherever you want a breakpoint, just put

debugger;

immediately before. This will work in Chrome and other Blink-based browsers (and also in Firefox I believe) as long as you have a dev tools open.

If you want to temporarily disable it, right click on the line number where "debugger" appears and choose "Never pause here".

Link to comment
Share on other sites

Completely agree with @in mono, using `debugger` is your easiest way to stop execution at a certain point, barring that there is always logging something, then clicking on it to find it in your source files and manually add a breakpoint. All modern browsers support this (breakpoints) but Chrome is the most advanced in this regard.

4 hours ago, Ludomancer said:

I looking for a way for browsers debugger to discover those files.

You mention files, do you have a build process? One that concatenates many files into one file to supply to the browser? If so, source maps are your friend, most build tools support building source maps, easiest is to append them to the end of your code bundle but you can also specify a separate file, add a small descriptor magic comment that tells the browser where to get the source map and then the browser will know how to build out the original source maps, usually mapping that to the bundle you have supplied. Many tools also include doing this even if your source is Typescript or ES2016/7, which is super amazing. Check out source maps and use a tool, don't write all that stuff yourself.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...