Coder Social home page Coder Social logo

vscode-debugger-extension-for-office-addins's Introduction

Microsoft Office Add-in Debugger for Visual Studio Code

The "Microsoft Office Add-in Debugger" Extension for Visual Studio Code allows you to use F5 to debug your Office Add-in against the Edge runtime.

This debugging mode is dynamic, allowing you to set breakpoints while code is running. You can see changes in your code immediately while the debugger is attached, all without losing your debugging session. Your code changes also persist, so you can see the results of multiple changes to your code. The following image shows this extension in action.

Microsoft Office Add-in Debugger Extension debugging Excel Add-in code

Prerequisites

These instructions assume you have experience using the command line, understand basic JavaScript, and have created an Office add-in project before using the Yo OfficeDev/ generator-office).

Install and use

  1. If you do not already have a project to work with, create a new project with the latest version of Yo Office. If you already have a project you would like to use, there is no need to create a new one.

  2. Open a command prompt as administrator Command prompt options, including "run as administrator" in Windows 10

To open Visual Studio Code as an administrator, select the run as administrator option when opening Visual Studio Code after searching for it in Windows.

  1. Navigate to your project directory.

  2. Run the following command to open your project in Visual Studio Code as an administrator

    code .
    

    Once Visual Studio Code is open, navigate manually to the project folder.

    To open Visual Studio Code as an administrator, select the run as administrator option when opening Visual Studio Code after searching for it in Windows.

  3. Within VS Code, select CTRL + SHIFT + X to open the Extensions bar. Search for the "Office Addin Debugger" extension and install it.

  4. In the .vscode folder of your project, you will find a launch.json file. At the end of the file, add the following code to the configurations section of the file.

	    {
	      "name": "Attach to Office Add-ins (Edge Legacy)",
	      "type": "office-addin",
	      "request": "attach",
	      "url": "https://localhost:3000/taskpane.html?_host_Info=HOST$Win32$16.01$en-US$$$$0",
	      "port": 9222,
	      "timeout": 45000,
	      "webRoot": "${workspaceFolder}",
	      "trace": "verbose",
	    },
	    {
	      "name": "Attach to Office Add-in (Edge Chromium)",
	      "type": "edge",
	      "request": "attach",
	      "useWebView": "advanced",
	      "port": 9229,
	      "timeout": 600000,
	      "webRoot": "${workspaceRoot}",
	      "trace": "verbose"
	    }
  1. In the section of JSON you just copied, find the "url" section. In this URL, you will need to replace the uppercase HOST text with the host application for your Office add-in. For example, if your Office add-in is for Excel, your URL value would be "https://localhost:3000/taskpane.html?_host_Info=Excel$Win32$16.01$en-US$$$$0".

  2. Open the command prompt and ensure you are at the root folder of your project. Run the command npm start to start the dev server. When your add-in loads in the Office host application, open the task pane.

  3. Return to Visual Studio Code and choose View > Debug or enter CTRL + SHIFT + D to switch to debug view.

  4. From the Debug options, choose Attach to Office Add-ins (Edge Chromium) or Attach to Office Add-ins (Edge Legacy) depending on which Edge version you have. Select F5 or choose Debug -> Start Debugging from the menu to begin debugging.

  5. Set a breakpoint in your project's task pane file. You can set breakpoints in VS Code by hovering next to a line of code and selecting the red circle which appears.

A red circle appears on a line of code in VS Code

  1. Run your add-in. You will see that breakpoints have been hit and you can inspect local variables.

Questions and comments

We'd love to get your feedback about this sample! You can send your feedback to us in the Issues section of this repository.

Open Source Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Copyright

Copyright (c) 2020 Microsoft Corporation. All rights reserved.

vscode-debugger-extension-for-office-addins's People

Contributors

millerds avatar tcourtneyowen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-debugger-extension-for-office-addins's Issues

Error processing "attach"

i have used edge(edgehtml)and change to webview
but still get the error

[vscode-debugger-extension-for-office-addins] Error processing "attach":connect ECONNREFUSED 127.0.0.1:9222

look forward to your kind reply

Debbuger doesn't stop at breakepoints

I'm trying to debug an Outlook Add-in in a desktop mode using settings in launch.json:
{
"name": "Outlook Desktop (Edge Chromium)",
"type": "pwa-msedge",
"request": "attach",
"useWebView": true,
"port": 9229,
"timeout": 600000,
"webRoot": "${workspaceRoot}",
"preLaunchTask": "Debug: Outlook Desktop",
"postDebugTask": "Stop Debug",
}

The output on the terminal looks like:

Executing task: npm run "start:desktop -- --app outlook" <

[email protected] start:desktop C:\Users\username\VSProjects\EmailO365AddOn
office-addin-debugging start manifest.xml desktop "--app" "outlook"

Debugging is being started...
App type: desktop
Enabled debugging for add-in 4acdb132-1567-4758-b88b-3b398147af35.
Starting the dev server... (webpack-dev-server --mode development)
The dev server is running on port 3000. Process id: 25948
Sideloading the Office Add-in...
Debugging started.

I can open my add-in in Outlook, but all breakpoints are ignored. How can I make them work?

I added "trace": true and got a log:

{
"tag":"runtime.launch",
"timestamp":1642629494741,
"message":"Error looking up /json/version",
"metadata":{
"ok":false,
"body":"connect ECONNREFUSED 127.0.0.1:9229",
"statusCode":503,
"error":{
"message":"Unexpected 503 response from http://localhost:9229/json/version: connect ECONNREFUSED 127.0.0.1:9229",
"stack":"Error: Unexpected 503 response from http://localhost:9229/json/version: connect ECONNREFUSED 127.0.0.1:9229
\n\tat b.fetchHttp (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1146792)
\n\tat runMicrotasks ()\n\tat processTicksAndRejections (internal/process/task_queues.js:93:5)
\n\tat async b.fetchJson (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1145926)
\n\tat async Promise.all (index 0)\n\tat async l (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1397969)
\n\tat async Object.retryGetBrowserEndpoint (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1398771)
\n\tat async Object.t.attach (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1386357)
\n\tat async S.acquireConnectionInner (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1355246)
\n\tat async S.acquireConnectionForBrowser (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1354873)
\n\tat async S.attemptToAttach (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1353260)
\n\tat async S.launch (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1352785)
\n\tat async t.Binder.captureLaunch (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1230057)
\n\tat async t.Binder._launch (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1229602)
\n\tat async Promise.all (index 10)\n\tat async t.Binder._boot (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1228654)
\n\tat async t.default._onMessage (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1321495)"
}
},
"level":0
}
......
{"tag":"runtime.launch","timestamp":1642701096269,"message":"Launch returned error",
"metadata":{"error":
{"message":
"Cannot connect to the target at localhost:9229:
Could not connect to debug target at http://localhost:9229: Could not find any debuggable target",
"stack":"Error: Cannot connect to the target at localhost:9229: Could not connect to debug target at http://localhost:9229: Could not find any debuggable target
\n\tat S.acquireConnectionForBrowser (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1354958)
\n\tat runMicrotasks ()\n\tat processTicksAndRejections (internal/process/task_queues.js:93:5)
\n\tat async S.attemptToAttach (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1353260)
\n\tat async S.launch (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1352785)
\n\tat async t.Binder.captureLaunch (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1230057)
\n\tat async t.Binder._launch (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1229602)
\n\tat async Promise.all (index 10)
\n\tat async t.Binder._boot (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1228654)
\n\tat async t.default._onMessage (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.js-debug\src\extension.js:2:1321495)"},
"wasCancelled":true,"name":"S"},"level":2}

Error processing "attach": connect ECONNREFUSED 127.0.0.1:9222

I use yo office build the Excel Javascript addin, follow the installation steps:

https://github.com/OfficeDev/vscode-debugger-extension-for-office-addins

When it goes to 8th step, run: npm start, it ask if allow the localhost loopback:

Debugging is being started...
App type: desktop
? Allow localhost loopback for Microsoft Edge WebView? Yes
Enabled debugging for add-in c9ec17d0-77f0-485a-ad1c-368d68f2f768.
Starting the dev server... (webpack serve --mode development)
The dev server is running on port 3000. Process id: 16836
Sideloading the Office Add-in...
Debugging started.

I choose yes as above, the Excel window popout with addin works well.
Then I try to start debug in VS Code, this error pop out.
image

I'm sure to use Admin about Powershell and VS Code.
Excel: 2016
npm:
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

launch.json:
        {
      "name": "Attach to Office Add-ins (Edge Legacy)",
      "type": "office-addin",
      "request": "attach",
      "url": "https://localhost:3000/taskpane.html?_host_Info=Excel$Win32$16.01$en-US$$$$0",
      "port": 9222,
      "timeout": 45000,
      "webRoot": "${workspaceFolder}",
      "trace": "verbose",
    }

Here a same question, but not nice solution for me till now (Dec 26)
https://stackoverflow.com/questions/36783068/cannot-connect-to-the-target-connect-econnrefused-127-0-0-19222

How to open an existing Excel file in debugger

Can I debug in an existing Excel file? I know that Visual Studio can but can't figure out how to do it in Visual Studio Code.

I use the default configuration "Excel Desktop (Edge Chromium)" in launch.json. Every time I press F5, it creates a new Excel file. The file name is the GUID in the Id tag in manifest.xml, such as a32c06d3-4bbb-4158-8b61-e0349f58019c.xlsx.

I saw this configuration runs a preLaunchTask "Debug: Excel Desktop". This task is specified in task.json:

"label": "Debug: Excel Desktop",
"type": "npm",
"script": "start:desktop -- --app excel,
"presentation": {
"clear": true,
"panel": "dedicated",
},
"problemMatcher": []

It is the "npm start:desktop -- --app excel" that creates the new Excel file.

I tried

npm start:desktop -- --app excel 'directory\filename'

But npm still creates the GUID named excel file instead of opening the file specified.

Debugging in Outlook?

I'm able to debug my add-in with the Edge tools, but not with VS Code. Should I be able to debug in Code?

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "office-addin",
      "request": "attach",
      "name": "Attach to Office Add-ins",
      "port": 9222,
      "trace": "verbose",
      "url": "https://localhost:3000/taskpane.html?_host_Info=Outlook$Win32$16.02$en-US$$$$0",
      "webRoot": "${workspaceFolder}",
      "timeout": 45000
    },
}

I launch with npm run dev-server

Debugging Outook stopped working

A week or two ago I could debug Outlook Add-Ins but since my last Outlook 365 update that no longer works. Office no longer prompts me with a Ok/Cancel message about starting a debugger.

Microsoft® Outlook® for Microsoft 365 MSO (16.0.14326.20164) 64-bit

Neither Port 9222 nor 9229 are being listened to.
{ "version": "0.2.0", "configurations": [ { "name": "Debug Office Add-in (Edge Chromium)", "type": "edge", "request": "attach", "useWebView": "advanced", "port": 9229, "timeout": 100000, "webRoot": "${workspaceRoot}" } ] }

image

image

I am able to run F12 and debug using the Edge DevTools.

C:\Windows\System32>netstat -an | find "92"
TCP 0.0.0.0:16992 0.0.0.0:0 LISTENING
TCP 10.0.0.184:49206 10.0.0.1:80 TIME_WAIT
TCP 10.0.0.184:49213 52.168.112.81:443 TIME_WAIT
TCP 10.0.0.184:49238 20.190.154.18:443 TIME_WAIT
TCP 10.0.0.184:49251 52.168.112.83:443 TIME_WAIT
TCP 10.0.0.184:49274 20.190.154.18:443 TIME_WAIT
TCP 10.0.0.184:49287 52.168.112.83:443 TIME_WAIT
TCP 10.0.0.184:56400 104.192.142.6:443 ESTABLISHED
TCP 10.0.0.184:64392 3.234.79.72:80 ESTABLISHED
TCP 127.0.0.1:12080 127.0.0.1:60927 ESTABLISHED
TCP 127.0.0.1:49261 127.0.0.1:49673 TIME_WAIT
TCP 127.0.0.1:60926 127.0.0.1:60928 ESTABLISHED
TCP 127.0.0.1:60927 127.0.0.1:12080 ESTABLISHED
TCP 127.0.0.1:60928 127.0.0.1:60926 ESTABLISHED
TCP 192.168.16.1:139 0.0.0.0:0 LISTENING
TCP [::]:16992 [::]:0 LISTENING
UDP 0.0.0.0:65292 :
UDP 127.0.0.1:60592 :
UDP 127.0.0.1:60928 :
UDP 192.168.16.1:67 :
UDP 192.168.16.1:68 :
UDP 192.168.16.1:137 :
UDP 192.168.16.1:138 :
UDP 192.168.16.1:1900 :
UDP 192.168.16.1:2177 :
UDP 192.168.16.1:60593 :
UDP [2601:589:8480:6400:68ef:492a:30d1:4b54]:2177 :

Attaches but no breakpoints?

Application is written in angular.

npm run script = 'ng serve [projectname --port 443 --ssl true --ssl-key c:\certificates\[key] --ssl-cert c:\certificates\[crt] --host [local domain name]'

Can debug Edge, and Chrome with breakpoints. Cannot achieve this with outlook addin.
Launch.json
{ "type": "chrome", "request": "launch", "name": "Launch Chrome against ssl [local domain name]", "url": "https://[local domain name]", "webRoot": "${workspaceFolder}" }, { "name": "Launch ssl [local domain name] in Microsoft Edge (Chromium) Canary", "type": "edge", "request": "launch", "version": "canary", "url": "https://[local domain name]", "webRoot": "${workspaceFolder}" }, { "type": "office-addin", "request": "attach", "name": "Attach to Office Add-ins", "port": 9222, "trace": "verbose", "sourceMaps": true, "url": "https://[local domain name]/index.html?_host_Info=Outlook$Win32$16.02$en-US$$$$0#/login", "webRoot": "${workspaceFolder}", "timeout": 45000 }

Would love to use vscode for this and not the Edge DevTools.

No longer works at all: ECONNREFUSED 127.0.0.1:9222 every time

I'm trying to attach to Outlook (Desktop, windows), but nothing at any point is opening any port 9222 - so the above error seems impossible to overcome.

Obviously, this is OUTLOOK.EXE - so I can't just "use a different browser" to solve this problem - it's not a browser.

I've re-followed all instructions on this page, many times, including reboots - it never works. I've got all the current versions of everything installed as of now (August 2021).

Visual Studio Code Debugger doesn't break at all for Excel Add-in

I follow the page below to create a Excel Add-in project with React and javascript.

https://docs.microsoft.com/en-us/office/dev/add-ins/quickstarts/excel-quickstart-jquery?tabs=yeomangenerator

When i try to run the add-in with debug following the page

https://docs.microsoft.com/en-us/office/dev/add-ins/testing/debug-with-vs-extension

The add-in can be started and is running correctly in Excel, however, all the breakpoints are not interruptting the exeution.

When i use the Microsoft Edge DevTool, The breakpoints are working fine.
https://www.microsoft.com/en-us/p/microsoft-edge-devtools-preview/9mzbfrmz0mnj?activetab=pivot:overviewtab

Please kindly check why the visual studio code attach is not working anymore.

VS Code not attaching with Office Running WebView2 Taskpanes

The launch event does not seem to attach (anymore?). I'm running 16.0.13012.2000 64-bit of Office. This does seem to run WebView2, could that be an issue? I think it is, as it also does not show the entry in Microsoft Edge Dev Tools but now you can use the 'attach debugger' in the Add-in Taskpane. This however now attaches to Edge Chromium.

I also tried setting the default browser to Edge (not chromium) or Chrome but to no effect.
Can you provide a working scenarion using Office 16.0.13012.2000?

My efforts are recorded and can be reviewed at https://youtu.be/Pd8IqpiCacg (been messing around for hours with this, so you need to have patience watching this 😁)

No Console Output

Windows 20H2 19042.746
Excel 16.0.13707 .20008 64bit

Taken a day of experimentation to understand how to attach the debugger in VS Code. Largely due to my system insisting on using Edge Legacy for webviews.

Now I have breakpoints, I find I don't have any console output in the VS Code Debug Console. Expected?

the debugger cannot be attached

I followed the steps described to attach the debugger, and it does not want to start, I get ECONNREFUSED message:
"[vscode-debugger-extension-for-office-addins] Error processing "attach": connect ECONNREFUSED 127.0.0.1:9222"

The json has the following configuration:
{
"type": "office-addin",
"request": "attach",
"name": "Attach to Office Add-ins",
"port": 9222,
"trace": "verbose",
"url": "https://localhost:3000/taskpane.html?_host_Info=Word$Win32$16.01$en-US$$$$0",
"webRoot": "${workspaceFolder}",
"timeout": 45000
}

On https://localhost:3000 I have data loaded, so the dev server seems to work fine.
This situation occurs for a brand new generated office addin.

Please advice. I am able to pay for the solution, if case. Thank you!

I would like to be able to use "urlFilter" in my launch.json entries.

I'd like to be able to do this in my launch.json :

      //  this doesn't work...
      // "urlFilter":
      //   "https://localhost:3000/*.html?_host_Info=Excel$Win32$16.01$en-US$$$$0",
      //                         ^^^^^   omg, i can haz wildcard, plz?  
      //                         along with param string containing special chars?

I posted a comment on vscode-chrome-debug, mentioning that I suspect that the root cause has to do with vscode-chrome-debug-core . I thought I'd mention it here, so that this project would be aware of how I was trying to use this extension.

https://github.com/microsoft/vscode-chrome-debug/issues/973#issuecomment-678708260

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.