Handle window.rezieTo in WebView2

홍준 이 20 Reputation points
2024-08-02T05:26:08.59+00:00

hello.

I am currently developing a Win32 C++ based WebView2 program.

I am writing this post because I have a question regarding WebView2.

I know that Webview2 API provides a callback that can be handled when calling window.open.

(add_NewWindowRequested and ICoreWebView2NewWindowRequestedEventHandler)

By setting put_Handled(true) to ICoreWebView2NewWindowRequestedEventArgs obtained within the callback, or using put_NewWindow, you can open the WebView2 window that you newly create.Alternatively, I understand that if the request is not handled, a popup created by the Edge engine itself will be displayed.

(In this case, if you enter window.chrome.webview into that window through developer tools, it will be displayed as undefined.)

Question)About this question, popups generated by the Edge engine (NewWindowRequested not handled) window.resizeTo works fine.

window.resizeTo does not work on newly created WebView2 windows via NewWindowRequested.

Q1) Is there a way to handle that event?

(Even if I checked with Spy++, no special events(window messsge) are received in the WebView 2 popup I created.)

(It seems that windows created in the Edge engine internally receive events through some means and adjust the window through SetWindowPos.)Q2) According to Mozilla MDN, for window.resizeTo to work, the window must be opened as a popup(not tab) and as window.open. Is the window opened with NewWindowRequested recognized as a 'tab'? In this case, is resizeTo not working due to policy?

If there is no other way, try to handle resize natively by calling postMessage in javascript.I've been struggling for a long time to find a solution to this problem.

help :(

Microsoft 365 and Office | Development | Office JavaScript API
Developer technologies | C++
Microsoft Edge | Microsoft Edge development
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-08-05T06:55:42.6433333+00:00

    Hi @홍준 이,

    I'm not quite sure how you implement it, but for some instructions regarding WebView2 window, I would suggest you read WebView2APISample, particularly the example of AppWindow.cpp. This file implements the application window in different ways.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,

    Shijie Li

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.