microsoft / ClearScript

A library for adding scripting to .NET applications. Supports V8 (Windows, Linux, macOS) and JScript/VBScript (Windows).
https://microsoft.github.io/ClearScript/
MIT License
1.74k stars 148 forks source link

V8ScriptEngine: Event OnDebuggerConnected? #518

Closed DavidBal closed 1 year ago

DavidBal commented 1 year ago

Hi ClearScript Team,

at the moment i am working on project that integrates your V8ScriptEngine.

I am now at a point where i would like to implement debugging. I would like know if there is a possibilty for a event that is fired when a Debugger is connected to the V8ScriptEngine? At the moment i am doing this as a workaround:

using (V8ScriptEngine scriptEngine = new V8ScriptEngine(V8ScriptEngineFlags.EnableTaskPromiseConversion | V8ScriptEngineFlags.EnableDateTimeConversion | V8ScriptEngineFlags.EnableDebugging | V8ScriptEngineFlags.AwaitDebuggerAndPauseOnStart ))
{
       if (debug)
       {
            scriptEngine.Evaluate("debugger;");
            DebuggerConnected?.Invoke(this, EventArgs.Empty);
        }

        //execute the Script ...
}

The problem with this workaround is that the user always starts in this empty script.

Is there a better way i can handle this case?

Thanks in advance for your answer.

Best regards, David

ClearScriptLib commented 1 year ago

Hi @DavidBal,

I am now at a point where i would like to implement debugging.

Please clarify: What kind of debugging features would you like to implement? ClearScript doesn't expose debugging APIs beyond enabling or disabling support for external debuggers.

Is there a better way i can handle this case?

Please tell us more about your scenario. When exactly would this event be fired? Would a matching DebuggerDetached event be required? What useful information might the event provide via EventArgs? What would the host do in response to this event?

Thanks!

DavidBal commented 1 year ago

Thank you for your answer!

Please clarify: What kind of debugging features would you like to implement? ClearScript doesn't expose debugging APIs beyond enabling or disabling support for external debuggers.

The tools that are used for debugging are VSCode, Google Chorme or Microsoft Edge. (Nothing special here.)

Please tell us more about your scenario. When exactly would this event be fired? Would a matching DebuggerDetached event be required? What useful information might the event provide via EventArgs? What would the host do in response to this event?

After a script is "started" from the user i prompt a dialog that the execution of the script is waiting for a debugger to be connected by the user. In this dialog the user also can cancel the waiting for a debugger (for that i am using CancelAwaitDebugger). At the moment i only need the information that a debugger has been connected, because then i can close the dialog that is telling the user "the script is waiting for a debugger to connect....".

Best regards, David

ClearScriptLib commented 1 year ago

Thanks, we'll take a closer look.

DavidBal commented 1 year ago

Thank you.

ClearScriptLib commented 1 year ago

Version 7.4.3 added the DebuggerConnected and DebuggerDisconnected events.