microsoft / azure-devops-extension-sdk

Client SDK for developing Azure DevOps extensions
MIT License
122 stars 38 forks source link

get WebConetxt not working in latest version (v3.1.2) #80

Open avijayarajait opened 1 year ago

avijayarajait commented 1 year ago

Hi Team, Unable to get WebConetxt and PageConext using azure-devops-extension-sdk latest version (v3.1.2) See below screen shot

On initialization:

image

Get webContext after initialization

image

So, it always returns following error message “Attempted to call getWebContext() before init() was complete

image

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.

zagaria commented 11 months ago

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.

TechnoRahmon commented 10 months ago

I have the same issue, in my extension if we enable : image

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 :

image

TechnoRahmon commented 10 months ago

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  */