简体   繁体   中英

Attach VS2010 to IE9 with PowerShell to debug javascript

Problem (from nuget PowerShell):

  • launch IIS Express (website is in a folder) [done]
  • launch IE9 to the URL [done]
  • attach current VisualStudio instance to IIS to debug .net code [done]
  • attach current VisualStudio instance to IE9 to debug Javascript code [PROBLEM]

Status:

Currently I'm able from powershell (with $DTE object) to attach VS to IIS and IE9 tab process. However I'm not able to debug javascript code (I think VS by default debugs only .net code and not Script).

I saw EnvDTE80.Transport, but I don't know how to use it inside nuget PowerShell. Do you have any idea to debug js? Or a completely different approach to the problem?

Update (8 August): I'm able to attach to IE9 debugging js BUT I found that my problem is completely different:

  • I run IIS Express with powershell
  • I run IE9 with powershell
  • I can get the "Process"es object

BUT I attach the debugger to the processes too early and debugging doesn't work.

  • I tried (ie) to start IIS Express, start IE9, attach first to IIS and then to IE9. Now I'm able to debug script but not to IIS Express.
  • I tried to stop the script 5 second (Start-Sleep -s 5) before attach DTE to processes and now I'm able to debug both IE js and IIS. But I don't like sleep solution (how many seconds?).

I haven't done this via the VS object model but via the GUI, when you attach to a running process like IE9, you can select which debugger type you want. In this case, you want the "Script" debugger. If this can be done by the GUI then I suspect that it can be done via the object model. The macro recorder in VS is good for figuring stuff like this out. I turned it on while I did the steps to attach via the GUI and got this:

Sub TemporaryMacro()
    Try
        Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
        Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
        Dim dbgeng(1) As EnvDTE80.Engine
        dbgeng(0) = trans.Engines.Item("Script")
        Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, "HILLR1").Item("iexplore.exe")
        proc2.Attach2(dbgeng)
    Catch ex As System.Exception
        MsgBox(ex.Message)
    End Try

End Sub

I use firebug to debug Javascript in Firefox. Chrome has its equivalent. Never tried in IE, but I think there is a Firebug version for IE.

Check this question: Firebug equivalent for Internet Explorer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM