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

WebResourceRequest is not executed for custom URI schemes in <iframe> #173

Closed
MarkusSchreiner opened this issue May 14, 2020 · 19 comments
Closed
Labels
feature request feature request tracked We are tracking this work internally.

Comments

@MarkusSchreiner
Copy link

MarkusSchreiner commented May 14, 2020

I have found the same problem with custom URI schemes as in issue #172 when they are used in an iframe:
example:
<iframe src="myProt:*AnotherPage.html"></iframe>

Also in this case the WebResourceRequest is not executed; setting the switches
--allow-file-access-from-files
and/or
--disable-web-security
does not help at this point.

Although I can intercept the loading of this frame with the ICoreWebView2NavigationStartingEventHandler, but I have no possibility to convert the URI into a corresponding real path; in this callback I don't have access to a any Response-object.

Any suggestion for this case?

AB#27223790

@david-risney david-risney added the feature request feature request label May 14, 2020
@david-risney
Copy link
Contributor

Yes, we don't support custom URI schemes whether in an iframe or otherwise.

If you know the iframe you could cancel the navigation and then inject script to navigate the iframe to a file URI. But the navigation event doesn't have an indication of which iframe so you would need to know that on your own somehow.

@MarkusSchreiner
Copy link
Author

Ok..

I think it would be important to support custom URI schemes.
Is the support planned in the near future?

@progsung
Copy link

progsung commented Nov 11, 2020

Any update?
"WebResourceRequest for custom URI schemes" is an important feature for anyone who wants to migrate from other browserControls(eg. chromely and cefsharp, they support well custom URI schemes).

Is the support planned in the near future?

@champnic
Copy link
Member

Support is planned, but probably not for another couple releases.

@champnic
Copy link
Member

Are you mostly using this for easy access of local file resources? If so we have a feature releasing sooner that may help. Details here: https://github.com/MicrosoftEdge/WebView2Feedback/blob/master/specs/HostResourceMapping.md

@MarkusSchreiner
Copy link
Author

No, I want to use the custom URIs to parse them and poll the corresponding resources from a database.

@romanan
Copy link

romanan commented Jan 27, 2021

+1 for custom protocol scheme support.
The application I am porting over from CEF has a custom scheme handler to handle local file access. I will try using the folder mapping API for now, but it looks a bit cumbersome since the file resource is an arbitrary location on the client's hard-drive (not a known folder), and we can have multiple file locations at the same time. We'd also like the same HTML to work on the Mac (Webkit) as well, which does not support file mapping, but does support custom schemes

@romanan
Copy link

romanan commented Feb 3, 2021

@champnic Just want to check if this is on the radar. I see that the VirtualHosting API is now promoted to stable in the latest prerelease (1.0.781-prerelease) so I will start working with that first, but please see the above comment on why I'd still prefer a custom scheme handler.

FWIW, our previous implementation in CEF used CefSchemeRegistrar::AddCustomScheme to register a scheme handler and CefStreamReader::CreateForFile to provide the resource stream when the handler was called

@champnic
Copy link
Member

champnic commented Feb 4, 2021

Hey @romanan - yes this is still on our radar, and relatively high priority on our backlog right now.

@romanan
Copy link

romanan commented Feb 4, 2021

Great news, thanks!

@MarkusSchreiner
Copy link
Author

Yes, very good that this issue is being addressed!

@maurawinstanley
Copy link
Contributor

maurawinstanley commented Aug 10, 2021

Thanks everyone for the feedback, we are starting to look into custom URI schemes again.
One of the places we draw inspiration from is the equivalent feature EdgeHTML WebView, where WebView essentially fires an event when we see a scheme we do not recognize, and the host can do whatever logic they want in the event handler - Reference doc.

Would this provide the support you are looking for, for custom URI schemes? If this event/handler was provided would you still need WebResourceRequested to fire for custom URI schemes?

Thanks.

@NewPagodi
Copy link

NewPagodi commented Aug 17, 2021

What I would like to see in custom URI schemes is something like RegisterNameSpace from the old mshtml/ie api. This function lets you associate a scheme with an IInternetProtocol object. (There are a few steps in between that I've left out, but that's the basic idea.)

The net result is that if I register the scheme "mycustomprotocol" in an application, when an mshtml object in my application trues to load content with a url such as "mycustomprotocol://mycustompage.html", it then call the read method for the associated IInternetProtocol object. The read method of that IInternetProtocol will be implemented to serve the content back to the mshtml object in whetever manner is appropriate for the application.

This was a very useful feature with the old api. Would handling the UnsupportedUriSchemeIdentified Event (or whetever the name ends up being) let you do something like this in the webview2 system?

@liminzhu
Copy link
Member

Hi folks! As @maurawinstanley mentioned we're currently working on custom protocol and it will looks similar to EdgeHTML's equivalent feature where you get an event when webview2 encounters an unrecognized protocol, and you can handle the event as appropriate. There area few things that planned to be exposed in the event handler -

  • Uri
  • IsUserInitiated
  • IsRedirected
  • NavigationId
  • Handled (if true, then we assume the host handled the event and wv2 will cancel the original navigation; otherwise the original passes through)
  • HandleDialog (if true, webview2 suppress the browser app protocol prompt if the protocol is a registered app protocol, e.g. msteams://)

Would love some feedback on whether approach solves your scenario and whether these info is enough or developers would want access to additional information/parameter as well in the event handler.

@MarkusSchreiner
Copy link
Author

As in issue #172 (comment of wusyong), perhaps it would be best to have the same properties as in CoreWebView2WebResourceRequestedEventArgs

@maurawinstanley
Copy link
Contributor

maurawinstanley commented Aug 24, 2021

@MarkusSchreiner thanks for the input, we are planning on having this event fire separately with these event args, and the WebResourceRequested event we are planning to have fire for custom URI schemes in the future. For this event separate of WebResourceRequested do these event args fit your scenario or are there additional ones you would like to see?

@Rezakarimi66
Copy link

@champnic @maurawinstanley Any update on this?

@david-risney
Copy link
Contributor

david-risney commented Sep 26, 2022

A near future prerelease SDK should have it as an experimental API.

@champnic
Copy link
Member

champnic commented Feb 1, 2023

This has shipped and should also work in iframes. see #172 (comment)

Thanks!

@champnic champnic closed this as completed Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request feature request tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

9 participants