MicrosoftEdge / MicrosoftEdge/WebView2Feedback

[Feature Request] TypeScript definitions for window.chrome.webview

Open
#4,194 0 comments 1 reaction 2 assignees View on GitHub

@Lakshmisha-KS is already working on this.

Since Feb 12, 2025.

feature request tracked
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Describe the feature/enhancement you need
Global TypeScript Interface for window.chrome.webview

The scenario/use case where you would use this feature
When developing using Typescript while using WebView2

Refer to the discussion for further context.

Discussed in https://github.com/MicrosoftEdge/WebView2Feedback/discussions/4028

Originally posted by danbahrami March 7, 2023
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;
            };
        };
    }
}

AB#40423422

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.