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

[Problem/Bug]: When using a custom scheme, opening a secondary window fails #4085

Closed
reynoldslabware opened this issue Oct 20, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@reynoldslabware
Copy link

What happened?

Our application uses a custom protocol (labware://labware).
Our first window loads successfully (bootstrap.html).
The top and bottom of the main console are shown below.
image

image

Our application then opens a second page using
window.open("whatever", "_blank")
That task page result is just grey for some reason. See the red error text in the console above.
image

It is odd that the tooltip for the main console log messages shows the custom scheme, things got loaded,
but the attempt to open another page seems to complain about the lack of a custom scheme
that seemed to have just worked.

In my support DLL which interfaces to WebView2 I do see logging entries for the main bootstrap page such as,

Navigate labware://labware/lwweb/bootstrap.html
myNavigationStartingEventHandler() called
WebResourceRequested labware://labware/lwweb/bootstrap.html
WebResourceRequested labware://labware/lwweb/css/common/lw-theme/jquery-ui-1.12.1.custom.css

I do not see such any such entries for the second page.
Any direction on what I should be looking at would be appreciated.

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Prerelease (Edge Canary/Dev/Beta)

Runtime Version

117.0.2045.31

SDK Version

No response

Framework

Win32

Operating System

Windows 10

OS Version

No response

Repro steps

This can be reproduced when using a custom schema and loading this HTML page

<html>
<script>
function test2()
{
 window.open("another.html", "_blank");
}
</script>
<body>
 <button >Test2</button>
</body>
</html>

With the another.html file containing

<html>
<body>
Hello world
</body>
</html>

Regression

No, this never worked

Last working version (if regression)

No response

@reynoldslabware reynoldslabware added the bug Something isn't working label Oct 20, 2023
@lflores-ms
Copy link
Contributor

@yildirimcagri-msft this looks like a bug?

@yildirimcagri-msft
Copy link
Member

This seems to be because the opened window is opened as a basic popup window and is not associated to a WebView2 and as a result the WebResourceRequest with the custom scheme cannot be handled by the app. For this to work, you'd need to associate a new WebView2 to the opened window by handling the NewWindowRequested event and setting NewWindow and then you can set a WebResourceRequested event handler on the new WebView2.

@reynoldslabware
Copy link
Author

Thank you for the guidance. It sounds like the high level steps to get this to cooperate
in the NewWindowRequestedEventHandler,
HRESULT myNewWindowRequestedEventHandler(
ICoreWebView2* sender, ICoreWebView2NewWindowRequestedEventArgs* args)
are:

  • get t(he deferal
    args->GetDeferral(&deferral);

  • create a new web view controller
    HRESULT cwvRc = m_env->CreateCoreWebView2Controller(hWndParent,
    Callback(...)
    )
    What should the parent window be?
    I guess the originating web view's parent because the originating web view itself
    may close independently of the about to be created web view.

  • use that controller to create a new web view

  • setup the new web view's callbacks including the WebResourceRequested callback

  • adjust the new web view's position and size as desired

  • adjust the initiating NewWindowRequestedEventArgs argument via
    args->put_NewWindow(newWebView);
    args->put_Handled(TRUE);

  • move the original NewWindowRequestedEventHandler call onward via
    deferral->Complete();

@reynoldslabware
Copy link
Author

reynoldslabware commented Oct 24, 2023

In CEF3 when we did a window.open() call a new Window was automatically created and the referenced URI content was shown within it. That new Window mapped logically to a new tab in a regular browser.
My approach above was close.
The parent window value above needs rethinking because I ended up with 2 web views in my main window. Oops.
Any thoughts on what the CEF3 world was doing for me automatically?

@reynoldslabware
Copy link
Author

I ended up creating a new empty window as the parent for the new web view2 instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants