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

Is there a way to toggle V8 engine into Debug state and await for debugger? #524

Closed 3da closed 1 year ago

3da commented 1 year ago

I want to toggle V8 engine into Debug state not from start. I want to execute some scripts and then turn on Debug mode.

Is it possible?

ClearScriptLib commented 1 year ago

Hi @3da,

I want to execute some scripts and then turn on Debug mode.

You can use DocumentFlags.AwaitDebuggerAndPause. Here's an example:

engine.AddHostType(typeof(Console));
engine.Execute("Console.WriteLine('This script runs immediately.')");
engine.Execute(
    new DocumentInfo { Flags = DocumentFlags.AwaitDebuggerAndPause },
    "Console.WriteLine('This script waits for a debugger connection.')"
);

However, that flag has some limitations. Please consult the documentation page.

Good luck!

3da commented 1 year ago

Thanks, great!