Skip to content

Commit 875e409

Browse files
john88bensonVesaJuvonen
authored andcommitted
JCB 052118 Debug Doc Updates (SharePoint#1884)
1 parent cef7d8a commit 875e409

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed
196 KB
Loading
239 KB
Loading

docs/spfx/debug-in-vscode.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ When building SharePoint Framework solutions that communicate with SharePoint, y
102102

103103
When building SharePoint Framework solutions, you will be doing such tests regularly, and it is a good idea to create a separate debug configuration for the hosted version of the SharePoint Workbench.
104104

105-
### Debug solution using hosted workbench
105+
### Debug Web Part solution using hosted workbench
106106

107107
1. Open launch.json, and update the `url` property under the *Hosted workbench* configuration to your SharePoint site URL.
108108

@@ -122,6 +122,63 @@ When building SharePoint Framework solutions, you will be doing such tests regul
122122

123123
![Breakpoint hit in Visual Studio Code when debugging a SharePoint Framework client-side web part in the hosted workbench](../images/vscode-debugging-breakpoint-hit-o365.png)
124124

125+
### Debug Extension solution using hosted workbench
126+
127+
Debuging an Extension in a hosted workbench is very similar to the steps for a Web Part with a few key differences.
128+
129+
130+
1. Open launch.json, and update the `url` property under the *Hosted workbench* configuration to your SharePoint site URL.
131+
132+
```json
133+
"url": "https://enter-your-SharePoint-site/_layouts/workbench.aspx",
134+
```
135+
136+
2. In Visual Studio Code, activate the **Debug** pane, and in the **Configurations** list, select the newly added **Hosted workbench** configuration.
137+
138+
![The hosted workbench configuration selected in the debug configurations drop-down in Visual Studio Code](../images/vscode-debugging-debugging-hosted-workbench.png)
139+
140+
3. After initiating the gulp serve in the Terminal start debugging either by selecting F5 or by selecting the **Start Debugging** option on the **Debug** menu. Visual Studio Code switches into debug mode, indicated by the orange status bar, and the Debugger for Chrome extension opens a new instance of Google Chrome with the Office 365 sign-in page.
141+
142+
![Office 365 login page displayed in Google Chrome after starting debugging in the hosted workbench](../images/vscode-debugging-o365-login.png)
143+
144+
4. In the workbench tab that was opened in your browser navigate to a SharePoint Online page that you wish to test your extension.
145+
146+
5. Append the following query string parameters to the URL. Notice that you need to update the ID to match your own extension identifier. This is available in the **HelloWorldApplicationCustomizer.manifest.json** file.
147+
148+
```json
149+
?loadSPFX=true&debugManifestsFile=https://localhost:4321/temp/manifests.js&customActions={"e5625e23-5c5a-4007-a335-e6c2c3afa485":{"___location":"ClientSideExtension.ApplicationCustomizer","properties":{"testMessage":"Hello as property!"}}}
150+
```
151+
152+
More detail about the URL query parameters:
153+
154+
* **loadSPFX=true**. Ensures that the SharePoint Framework is loaded on the page. For performance reasons, the framework does not load unless at least one extension is registered. Because no components are registered, you must explicitly load the framework.
155+
156+
* **debugManifestsFile**. Specifies that you want to load SPFx components that are locally served. The loader only looks for components in the app catalog (for your deployed solution) and the SharePoint manifest server (for the system libraries).
157+
158+
* **customActions**. Simulates a custom action. When you deploy and register this component in a site, you'll create this **CustomAction** object and describe all the different properties you can set on it.
159+
* **Key**. Use the GUID of the extension as the key to associate with the custom action. This has to match the ID value of your extension, which is available in the extension manifest.json file.
160+
* **Location**. The type of custom action. Use `ClientSideExtension.ApplicationCustomizer` for the Application Customizer extension.
161+
* **Properties**. An optional JSON object that contains properties that are available via the **this.properties** member. In this HelloWorld example, it defined a `testMessage` property.
162+
163+
The full URL should look similar to the following:
164+
165+
```json
166+
contoso.sharepoint.com/Lists/Contoso/AllItems.aspx?loadSPFX=true&debugManifestsFile=https://localhost:4321/temp/manifests.js&customActions={"e5625e23-5c5a-4007-a335-e6c2c3afa485":{"___location":"ClientSideExtension.ApplicationCustomizer","properties":{"testMessage":"Hello as property!"}}}
167+
```
168+
169+
6. Select **Load debug scripts** to continue loading scripts from your local host.
170+
171+
![Allow Debug Manifest question from the page](../images/ext-app-debug-manifest-message.png)
172+
173+
<br/>
174+
When the page loads you should now be able to see the Extension on your page(in this case a list view command extension):
175+
176+
![Hitting Breakpoints in the Visual Studio Code](../images/debug-Extension-Loaded.png)
177+
178+
In addition you can now toggle Breakpoints and step through the code:
179+
180+
![Hitting Breakpoints in the Visual Studio Code](../images/debug-Extension-Breakpoints.png)
181+
125182
## Debugging with Microsoft Edge or older projects
126183
127184
If you are using an older version of SharePoint Framework Yeoman generator or want to debug with Microsoft Edge, follow these steps to create the launch.json file manually.

0 commit comments

Comments
 (0)