Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set-VSCodeHtmlContentView not working / not adding any content to the tab body [Deprecated API] #4872

Open
6 tasks done
strxngewxrld opened this issue Dec 28, 2023 · 12 comments
Assignees
Labels
Area-HTML Content View Issue-Bug A bug to squash. Up for Grabs Will shepherd PRs.

Comments

@strxngewxrld
Copy link

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

With the vscode-powershell extension comes the PowerShellEditorServices.VSCode module.
These functions were first introduced with extension version 1.4.0.

I have tried to run the snippet that is described in the release notes, but the Set-VSCodeHtmlContentView doesn't add content to the tab body, the Write-VSCodeHtmlContentView cmdlet doesn't work either.

The problem occurs on both Windows and MacOS.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Darwin 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : Visual Studio Code Host
Version          : 2023.8.0
InstanceId       : 9f942f6f-8367-4a6c-bff7-d2ef1bbb8a49
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

Version: 1.85.1 (Universal)

Extension Version

ms-vscode.powershell@v2023.8.0

Steps to Reproduce

Run the snippet described in the release notes:

$view = New-VSCodeHtmlContentView -Title "My Custom View" -ShowInColumn One
Set-VSCodeHtmlContentView -View $view -Content "<h1>Hello world!</h1>"
Write-VSCodeHtmlContentView $view -Content "<b>I'm adding new content!</b><br />"

Visuals

5a2b9c95-a9a2-4b29-8c90-7cbcc9027d0c

Logs

The console log in the vscode developer tools shows the following entries:

webviewElement.ts:513 An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can escape its sandboxing.
mountTo @ webviewElement.ts:513
M @ overlayWebview.ts:218
claim @ overlayWebview.ts:120
ib @ webviewEditor.ts:178
setInput @ webviewEditor.ts:169
await in setInput (async)
S @ editorPanes.ts:445
L @ editorPanes.ts:270
openEditor @ editorPanes.ts:146
(anonymous) @ editorGroupView.ts:1111
Eb @ editorGroupView.ts:1135
Db @ editorGroupView.ts:1093
openEditor @ editorGroupView.ts:999
openEditor @ editorService.ts:551
openWebview @ webviewWorkbenchService.ts:285
$createWebviewPanel @ mainThreadWebviewPanels.ts:167
S @ rpcProtocol.ts:456
Q @ rpcProtocol.ts:441
M @ rpcProtocol.ts:371
L @ rpcProtocol.ts:297
(anonymous) @ rpcProtocol.ts:161
y @ event.ts:1148
fire @ event.ts:1179
fire @ ipc.net.ts:650
x.onmessage @ localProcessExtensionHost.ts:374
index.html?id=14dfbeda-8d05-4dfe-b50a-7b8119b638b7&origin=ec1b4a75-ad64-403d-b5e6-2c1d782bc3e3&swVersion=4&extensionId=ms-vscode.powershell&platform=electron&vscode-resource-base-authority=vscode-resource.vscode-cdn.net&parentOrigin=vscode-file%3A%2F%2Fvscode-app:273

No service worker controller found. Waiting for controllerchange.

@strxngewxrld strxngewxrld added Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed! labels Dec 28, 2023
@JustinGrote
Copy link
Collaborator

@strxngewxrld thanks for the report! These were implemented a long time ago before a major rewrite and likely don't have any tests and were broken as a result.

@andyleejordan is this something to fix or deprecate?

@JustinGrote JustinGrote added Area-HTML Content View Needs: Maintainer Attention Maintainer attention needed! and removed Needs: Triage Maintainer attention needed! labels Dec 30, 2023
@strxngewxrld
Copy link
Author

@JustinGrote, @andyleejordan I personally think that's a cool feature for many applications. For example this could be the foundation for a new Out-GridView like function that works inside DevContainers, remote sessions, etc. Also good for reporting or even building small applications like with WinForms back in the days.

@andyleejordan
Copy link
Member

Unfortunately I would probably lean toward deprecating given that these have probably been broken for a long time and not reported as such until now. That said, if you can track down the last known working version of the extension that would go a long way toward us being to fix them instead.

@strxngewxrld
Copy link
Author

Perhaps the community isn't aware of this feature at all? It is only mentioned in the 1.4.0 release notes and in an older issue about the possibility of adding css/js support. I stumbled upon this feature while doing some other research.

I tested a lot of extension versions with the same vs code version now and never got the feature to work:

VS Code 1.85.1
pwsh extension 1.4.0
pwsh 5.1.17763.5202

[Extension Host] stack trace: TypeError: The "cb" argument must be of type function. Received undefined
    at maybeCallback (node:fs:189:3)
    at Object.appendFile (node:fs:2298:14)
    at Logger.writeLine (c:\Users\user1\.vscode\extensions\ms-vscode.powershell-1.4.0\src\logging.ts:143:16)
    at Logger.writeAtLevel (c:\Users\user1\.vscode\extensions\ms-vscode.powershell-1.4.0\src\logging.ts:52:18)
    at Logger.write (c:\Users\user1\.vscode\extensions\ms-vscode.powershell-1.4.0\src\logging.ts:61:14)
    at c:\Users\user1\.vscode\extensions\ms-vscode.powershell-1.4.0\src\session.ts:341:30
w @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:39
S @ rpcProtocol.ts:456
Q @ rpcProtocol.ts:441
M @ rpcProtocol.ts:371
L @ rpcProtocol.ts:297
(anonymous) @ rpcProtocol.ts:161
y @ event.ts:1148
fire @ event.ts:1179
fire @ ipc.net.ts:650
x.onmessage @ localProcessExtensionHost.ts:374
mainThreadExtensionService.ts:81 [ms-vscode.PowerShell]The "cb" argument must be of type function. Received undefined
$onExtensionRuntimeError @ mainThreadExtensionService.ts:81
S @ rpcProtocol.ts:456
Q @ rpcProtocol.ts:441
M @ rpcProtocol.ts:371
L @ rpcProtocol.ts:297
(anonymous) @ rpcProtocol.ts:161
y @ event.ts:1148
fire @ event.ts:1179
fire @ ipc.net.ts:650
x.onmessage @ localProcessExtensionHost.ts:374
mainThreadExtensionService.ts:82 TypeError: The "cb" argument must be of type function. Received undefined
    at maybeCallback (node:fs:189:3)
    at Object.appendFile (node:fs:2298:14)
    at Logger.writeLine (c:\Users\user1\.vscode\extensions\ms-vscode.powershell-1.4.0\src\logging.ts:143:16)
    at Logger.writeAtLevel (c:\Users\user1\.vscode\extensions\ms-vscode.powershell-1.4.0\src\logging.ts:52:18)
    at Logger.write (c:\Users\user1\.vscode\extensions\ms-vscode.powershell-1.4.0\src\logging.ts:61:14)
    at c:\Users\user1\.vscode\extensions\ms-vscode.powershell-1.4.0\src\session.ts:341:30

VS Code 1.85.1
pwsh extension 1.4.3
pwsh 5.1.17763.5202

[Extension Host] rejected promise not handled within 1 second: Error: command 'vscode.previewHtml' not found
w @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:39
S @ rpcProtocol.ts:456
Q @ rpcProtocol.ts:441
M @ rpcProtocol.ts:371
L @ rpcProtocol.ts:297
(anonymous) @ rpcProtocol.ts:161
y @ event.ts:1148
fire @ event.ts:1179
fire @ ipc.net.ts:650
x.onmessage @ localProcessExtensionHost.ts:374
console.ts:137 [Extension Host] stack trace: Error: command 'vscode.previewHtml' not found
    at k.n (vscode-file://vscode-app/c:/Program%20Files/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1538:12339)
    at k.executeCommand (vscode-file://vscode-app/c:/Program%20Files/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1538:12268)
w @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:39
S @ rpcProtocol.ts:456
Q @ rpcProtocol.ts:441
M @ rpcProtocol.ts:371
L @ rpcProtocol.ts:297
(anonymous) @ rpcProtocol.ts:161
y @ event.ts:1148
fire @ event.ts:1179
fire @ ipc.net.ts:650
x.onmessage @ localProcessExtensionHost.ts:374
log.ts:441   ERR command 'vscode.previewHtml' not found: Error: command 'vscode.previewHtml' not found
    at k.n (vscode-file://vscode-app/c:/Program%20Files/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1538:12339)
    at k.executeCommand (vscode-file://vscode-app/c:/Program%20Files/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1538:12268)

VS Code 1.85.1
pwsh extension 1.5.0 / 1.12.1
pwsh 5.1.17763.5202

console.ts:137 [Extension Host] rejected promise not handled within 1 second: Error: command 'vscode.previewHtml' not found
w @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:39
S @ rpcProtocol.ts:456
Q @ rpcProtocol.ts:441
M @ rpcProtocol.ts:371
L @ rpcProtocol.ts:297
(anonymous) @ rpcProtocol.ts:161
y @ event.ts:1148
fire @ event.ts:1179
fire @ ipc.net.ts:650
x.onmessage @ localProcessExtensionHost.ts:374
console.ts:137 [Extension Host] stack trace: Error: command 'vscode.previewHtml' not found
    at k.n (vscode-file://vscode-app/c:/Program%20Files/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1538:12339)
    at k.executeCommand (vscode-file://vscode-app/c:/Program%20Files/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1538:12268)
w @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:39
S @ rpcProtocol.ts:456
Q @ rpcProtocol.ts:441
M @ rpcProtocol.ts:371
L @ rpcProtocol.ts:297
(anonymous) @ rpcProtocol.ts:161
y @ event.ts:1148
fire @ event.ts:1179
fire @ ipc.net.ts:650
x.onmessage @ localProcessExtensionHost.ts:374
log.ts:441   ERR command 'vscode.previewHtml' not found: Error: command 'vscode.previewHtml' not found
    at k.n (vscode-file://vscode-app/c:/Program%20Files/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1538:12339)
    at k.executeCommand (vscode-file://vscode-app/c:/Program%20Files/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1538:12268)

VS Code 1.85.1
pwsh extension 2019.5.0
pwsh 5.1.17763.5202

No service worker controller found. Waiting for controllerchange.

I have also looked in the source code of the extension versions, but haven't found any clue. @andyleejordan would it be possible for me to take a look into the Microsoft.PowerShell.EditorServices.VSCode.dll for further investigation?

@andyleejordan
Copy link
Member

andyleejordan commented Jan 5, 2024

Thanks so much for your testing! It looks like the features were implemented against APIs in VS Code that have since been removed (e.g. vscode.previewHtml) which unfortunately makes this much harder to bring back.

@andyleejordan
Copy link
Member

andyleejordan commented Jan 5, 2024

Info I found on its removal/deprecation: microsoft/vscode#62630

@andyleejordan
Copy link
Member

andyleejordan commented Jan 5, 2024

It looks like Tyler got the CustomViews migrated to the new API but the ContentView stuff was missed: #1602

@andyleejordan andyleejordan added the Up for Grabs Will shepherd PRs. label Jan 5, 2024
@SydneyhSmith
Copy link
Collaborator

Given that the apis got deprecated, and we don't have the resources to maintain in in the current state our plan is to remove the command for the time being....we would be open to a design proposal as to how to do this more maintainably...thanks!

@SydneyhSmith SydneyhSmith removed the Needs: Maintainer Attention Maintainer attention needed! label Jan 10, 2024
@SydneyhSmith SydneyhSmith changed the title Set-VSCodeHtmlContentView not working / not adding any content to the tab body Set-VSCodeHtmlContentView not working / not adding any content to the tab body [Deprecated API] Jan 10, 2024
@andyleejordan
Copy link
Member

Correction: on closer inspection it does look like all the stuff was migrated from that deprecated API, but it has all still been broken for quite a while (my guess is another VS Code change), at least a year as I tested v2023.1.0 to the same effect (opens a "view" but it's empty).

So unfortunately I think our decision stands. As it took a year (presumably, maybe a more recent VS Code update is what broke it) to come up that indicates its usage is too low for us to go about fixing. If someone wants to figure it out we'll be happy to take a PR. For now we're removing the code (which is also a massive simplification because it was the entirety of the "VSCode" module we had to build and ship with the extension).

@JustinGrote
Copy link
Collaborator

@strxngewxrld when that code was written, webviews didn't exist in vscode, they do now:
https://code.visualstudio.com/api/extension-guides/webview

So that would be a better route. As a perhaps future enhancement, the PS extension could facilitate starting a webview from a PowerShell script that hosts a Pode instance or whatnot as a go forward approach.

@SeeminglyScience
Copy link
Collaborator

Perhaps the community isn't aware of this feature at all? It is only mentioned in the 1.4.0 release notes and in an older issue about the possibility of adding css/js support. I stumbled upon this feature while doing some other research.

So I'm notorious for being the one person who was using X feature in a project and now it can't be cut. I was there when this was released, and I can tell you that the underlying API was so locked down that it was borderline useless and even I couldn't get anything useful working. It's one of those things that only really worked if you were shipping an extension with static files.

I'm sure some similar in theme commands could be made with the newer APIs but it'd be a completely different command shape so it becomes more of a feature request than a bug. I'd also personally say that it would likely be too much code to review and maintain even if it was graciously done as a PR by the community.

This is another scenario where it would be most ideal if we instead had a way for folks to make extensions that can interact with the PSES runspace in some way. That would let the community implement their own extension to provide that functionality. This is a long term plan of mine but it's not funded atm and my free time is a little short for the time being.

@JustinGrote
Copy link
Collaborator

JustinGrote commented Jan 18, 2024

Perhaps the community isn't aware of this feature at all? It is only mentioned in the 1.4.0 release notes and in an older issue about the possibility of adding css/js support. I stumbled upon this feature while doing some other research.

So I'm notorious for being the one person who was using X feature in a project and now it can't be cut. I was there when this was released, and I can tell you that the underlying API was so locked down that it was borderline useless and even I couldn't get anything useful working. It's one of those things that only really worked if you were shipping an extension with static files.

I'm sure some similar in theme commands could be made with the newer APIs but it'd be a completely different command shape so it becomes more of a feature request than a bug. I'd also personally say that it would likely be too much code to review and maintain even if it was graciously done as a PR by the community.

This is another scenario where it would be most ideal if we instead had a way for folks to make extensions that can interact with the PSES runspace in some way. That would let the community implement their own extension to provide that functionality. This is a long term plan of mine but it's not funded atm and my free time is a little short for the time being.

Agreed, being able to submit stuff to the PSES runspace "pipeline" and get serialized/jsonified stuff back over some kind of IPC would be great, I know the scaffolding for the plugin API is there, but all you can really do at this point is get the version of PS in use (which Pester Tests does in fact register and use so its background version matches what PSES is using)

Pester tests has a library that does this very thing that I eventually plan to spin out into its own NPM package https://github.com/pester/vscode-adapter/blob/main/src/powershell.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-HTML Content View Issue-Bug A bug to squash. Up for Grabs Will shepherd PRs.
Projects
Status: Wishlist
Development

No branches or pull requests

5 participants