Skip to content

TypeScript definitions for window.chrome.webview #3273

@danbahrami

Description

@danbahrami

Hi, I'm looking through the WebView2 docs and can't find any API reference for window.chrome.webview. Specifically I'm looking to define a global TypeScript interface for window.chrome.webview.postMessage and window.chrome.webview.addEventListener.

I have a couple of questions:

1. What's the method for removing event listeners?

I can't tell if window.chrome.addEventListener returns an unsubscribe callback or if there's an adjacent removeEventListener that behaves the same as adding/removing DOM events.

2. Do you have a recommendation for a global TypeScript definition?

Here's what I've got so far but I'm not sure if it's accurate

declare global {
    interface Window {
        chrome?: {
            webview?: {
                addEventListener: (
                    message: string,
                    handler: (event: any) => void, // not sure yet what the event type should be
                ) => void;
                postMessage: (message: string) => void;
            };
        };
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions