I just want to automate the insertion of a js script in the console window, and execute it, like this:
I tried to use the
Chrome.Runtime.EnableCommand class, then a
Chrome.Runtime.CompileScriptCommand, but nothing happens when I try to get the resulting
CommandResponse object (which I never get) when calling and awaiting the
I also tried the same but using
Chrome.Debugger.EnableCommand class and
Chrome.Debugger.SetScriptSourceCommand, just trying for try experimenting things, because I don’t know what member I should use in this library.
Well, to show what I tried with the library, in VB.NET, I just took the C# MasterDevs usage example from GitHub and tried to find the right command to compile a script:
Imports MasterDevs.ChromeDevTools Imports MasterDevs.ChromeDevTools.Protocol Task.Run( Async Sub() Dim chromeProcessFactory = New ChromeProcessFactory(New StubbornDirectoryCleaner()) Using chromeProcess As IChromeProcess = chromeProcessFactory.Create(9222, True) Dim sessionInfo As ChromeSessionInfo = (chromeProcess.GetSessionInfo().Result).LastOrDefault() Dim chromeSessionFactory = New ChromeSessionFactory() Dim chromeSession = chromeSessionFactory.Create(sessionInfo.WebSocketDebuggerUrl) Dim runtimeEnable As New Chrome.Runtime.EnableCommand Dim runtimeEnableResponse As CommandResponse(Of Chrome.Runtime.EnableCommandResponse) = Await chromeSession.SendAsync(runtimeEnable) Dim debuggerEnable As New Chrome.Debugger.EnableCommand Dim debuggerEnableResponse As CommandResponse(Of Chrome.Debugger.EnableCommandResponse) = Await chromeSession.SendAsync(debuggerEnable) Dim compileScript As New Chrome.Runtime.CompileScriptCommand compileScript.Expression = .Value Dim compileScriptResponse As CommandResponse(Of Chrome.Runtime.CompileScriptCommandResponse) = Await chromeSession.SendAsync(compileScript) Dim setScriptSource As New Chrome.Debugger.SetScriptSourceCommand() setScriptSource.ScriptSource = .Value Dim setScriptSourceResponse As CommandResponse(Of Chrome.Debugger.SetScriptSourceCommandResponse) = Await chromeSession.SendAsync(setScriptSource) End Using End Sub).Wait()
…note that my code is trash, because it does nothing of the expected things more than opening a new chome instance.
The reason why I’m using the
Chrome.XXXXX.EnableCommand classes is because I found this question and its answer: https://groups.google.com/forum/#!topic/chrome-debugging-protocol/tmgIQrkr5zI and since the lack of XML documentation in MasterDevs lib, I think the
Enablecommand classes are equivalents to what says in that answer from google groups, and because what the answer says, it seems required to use the
EnableCommand class before nothing… but I’m really not sure whether
Chrome.Runtime.Enablecommand class is a equivalent of
Runtime.enable, neither whether I used it properly…
My question is:
how can I use the MasterDevs ChromeDevTools library in C# or VB.NET to insert a js code snippet in the Chrome’s console window and then execute it?.