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

In addition to WebviewPanel, let WebviewView also support transferring of TypedArrays #148429

Merged
merged 1 commit into from Apr 30, 2022

Conversation

ShenHongFei
Copy link
Contributor

This PR fixes #115807

Currently webviews created with window.createWebviewPanel can send ArrayBuffer via postMessage, but webviews registered via window.registerWebviewViewProvider cannot. The two cases behave inconsistently

@mjbvz
@Tyriar

const html = `
    <!doctype html>
    <html>
        <head>
            <meta charset='utf-8' />
            <title>Webview</title>
        </head>
        <body>
            <script>
                let vscode = acquireVsCodeApi()
                
                const buffer = new ArrayBuffer(10)
                
                vscode.postMessage(buffer, [buffer])
            </script>
        </body>
    </html>
`

// WebviewView, registered as a webview view in view container
window.registerWebviewViewProvider(
    'bufferview',
    {
        async resolveWebviewView (view, ctx, canceller) {
            view.webview.options = {
                enableScripts: true,
            }
            
            view.webview.onDidReceiveMessage(event => {
                event instanceof ArrayBuffer // false, event is currently { }
            })
            
            view.webview.html = html
        }
    }
)


// WebviewPanel
let panel = window.createWebviewPanel(
    'bufferpanel',
    'bufferpanel',
    {
        preserveFocus: true,
        viewColumn: ViewColumn.Two,
    },
    {
        enableScripts: true,
    }
)

panel.webview.onDidReceiveMessage(event => {
    event instanceof ArrayBuffer // true
})

panel.webview.html = html

@ghost
Copy link

ghost commented Apr 29, 2022

CLA assistant check
All CLA requirements met.

@mjbvz mjbvz added this to the May 2022 milestone Apr 30, 2022
@mjbvz mjbvz merged commit 19e728a into microsoft:main Apr 30, 2022
@mjbvz
Copy link
Contributor

mjbvz commented Apr 30, 2022

Thanks! Good find

aeschli pushed a commit that referenced this pull request May 2, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jun 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve transfer of ArrayBuffers to and from webviews
2 participants