get WebConetxt not working in latest version (v3.1.2)
avijayarajait opened this issue · 3 comments
Hi Team,
Unable to get WebConetxt and PageConext using azure-devops-extension-sdk latest version (v3.1.2)
See below screen shot
On initialization:
Get webContext after initialization
So, it always returns following error message “Attempted to call getWebContext() before init() was complete”
Could you please check this issue?
(OR)
Guide me how to get webContext.host.uri value without using webContext in React JS ?
Thanks in advance.
Thanks,
Vijayaraj A.
Based on my investigation, it appears that this is not possible because the pageContext and webContext objects are empty in the new SDK (as per the API response). However, these objects exist for the old SDK (https://github.com/microsoft/vss-web-extension-sdk).
With the old SDK, everything works as expected. In the new SDK, we can replace the new API calls with the old ones based on https://github.com/microsoft/vss-web-extension-sdk/blob/master/lib/VSS.SDK.js#L852, but this would require applying additional patches.
I have the same issue, in my extension if we enable :
Then the following code will throw an error
code :
SDK.init().then(()=>{
const projectContext = SDK.getWebContext().project;
SDK.register("id", () => {
return {
execute: (context:any)=>openHomePanel(context, projectContext)
}
});
});
the target is "ms.vss-work-web.backlog-item-menu"
and the type is "type": "ms.vss-web.action"
Error :
I just used different approach to get the current project, I used SDK.getService<IProjectPageService>
here is my new function :
/* begin:: Gets the project associated with the current page */
const getProject = async ()=>{
const projectService = await SDK.getService<IProjectPageService>(CommonServiceIds.ProjectPageService);
return await projectService.getProject();
}
/* end:: Gets the project associated with the current page */