Skip to content

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

Merged
mjbvz merged 1 commit intomicrosoft:mainfrom
ShenHongFei:webview-view-typed-array-transfer
Apr 30, 2022
Merged

In addition to WebviewPanel, let WebviewView also support transferring of TypedArrays#148429
mjbvz merged 1 commit intomicrosoft:mainfrom
ShenHongFei:webview-view-typed-array-transfer

Conversation

@ShenHongFei
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
Collaborator

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