Repository navigation
Closed
Labels
area-System.NetenhancementProduct code improvement that does NOT require public API changes/additions
Milestone
Description
Is your feature request related to a problem? Please describe.
When I try to develop a browser extension by blazor. I have to fetch some resources hosts in extensions://* protocol by HttpClient.
But it throw a exception like:
blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Only 'http', 'https', and 'blob' schemes are allowed. (Parameter 'requestUri')
System.ArgumentException: Only 'http', 'https', and 'blob' schemes are allowed. (Parameter 'requestUri')
at System.Net.Http.HttpRequestMessage.InitializeValues(HttpMethod method, Uri requestUri)
at System.Net.Http.HttpRequestMessage..ctor(HttpMethod method, Uri requestUri)
at System.Net.Http.HttpClient.CreateRequestMessage(HttpMethod method, Uri uri)
at System.Net.Http.HttpClient.GetStreamAsync(Uri requestUri, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.GetStreamAsync(Uri requestUri)
at System.Net.Http.HttpClient.GetStreamAsync(String requestUri)
at Newbe.Blazors.TryNet.Pages.Index.Compile(String text, MetadataReference[] additionalReferences) in D:\Repo\newbe\Newbe.Demo\src\BlogDemos\Newbe.Blazor\Newbe.Blazors.TryNet\Newbe.Blazors.TryNet\Pages\Index.cs:line 64
at Newbe.Blazors.TryNet.Pages.Index.CompileAndEncode(String text, MetadataReference[] additionalReferences) in D:\Repo\newbe\Newbe.Demo\src\BlogDemos\Newbe.Blazor\Newbe.Blazors.TryNet\Newbe.Blazors.TryNet\Pages\Index.cs:line 49
at Newbe.Blazors.TryNet.Pages.Index.OnClickRunAsync() in D:\Repo\newbe\Newbe.Demo\src\BlogDemos\Newbe.Blazor\Newbe.Blazors.TryNet\Newbe.Blazors.TryNet\Pages\Index.cs:line 86
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)Describe the solution you'd like
A clear and concise description of what you want to happen. Include any alternative solutions you've considered.
Please allow some additional schema like 'extensions' by some Property in HttpClient class.
Metadata
Metadata
Assignees
Labels
area-System.NetenhancementProduct code improvement that does NOT require public API changes/additions
Activity
javiercn commentedon May 17, 2021
@newbe36524 thanks for contacting us.
This is a question for the dotnet/runtime folks
karelz commentedon May 17, 2021
@newbe36524 what is "extensions://* protocol"? I never heard of that. What does it do? What's the protocol?
As the exception says,
HttpClientdoes not support it -- evenUridoes not support it.Is it something that JavaScript / WebAssembly natively support? If yes, then it would be feature request for .NET WebAssembly I assume ...
newbe36524 commentedon May 17, 2021
I can develop a chrome extension by Blazor WebAssembly. just like this project https://github.com/newbe36524/Amazing-Favorites.
In this way, I can using C# to build a chrome extensions.
However, if I want to request a resource such as extension://gglgheekopdecoeeinlggdmedamjbjpj/sample.json by HttpClient. The exception raised
newbe36524 commentedon May 17, 2021
Actually, I try to port a Blazor WebAssembly project from hosted style into to chrome extension style. But block by if I want to send a request with extensions://* protocol since all files is host in extensions folder instead of a web server.
It will throw a exception by HttpClient as the code below:
https://github.com/BlazorRepl/BlazorRepl/blob/master/Core/CompilationService.cs#L233
karelz commentedon May 17, 2021
It is still not clear to me what is the "extensions://*" protocol? Is it just HTTP? Or something else?
How does JavaScript or something else communicate with such endpoints?
That will answer the question if it is something
HttpClientin WebAssembly might want to support or not.newbe36524 commentedon May 17, 2021
Just like http but they are real files hosted by browser extensions and target to browser extensions folder.

Take edge as a example.
I open extensions
click any one of backgroud page of a extensions

dev tool will show as below, and refresh dev tools by F5, you can find networks details, and open anyone of them that target to chrome-extensions:// and "open it in new tab", you could find url with extensions://*


For MS Edge, They are some files place at C:\Users[User]\AppData\Local\Microsoft\Edge\User Data\Default\Extensions[ExtenstionId][version]
BenLampson commentedon May 17, 2021
The extensions://* is chrome or the chromium system's private "extends manager protocol"
it's full string is : chrome-extension://<extensionID>/<pathToFile>
extensionID is target extendsid,
path to file is the relative path about the extends folder.
You can think that is chromium's private file protocol, like file:\.....
wfurt commentedon May 19, 2021
It seems inappropriate for generic framework like .NET HttpClient to worry about other product private guts. It seems like some kind of external package would be much more appropriate.
newbe36524 commentedon May 20, 2021
@wfurt In fact now, I am limited by this line of code because its requirements must be within the given range.
runtime/src/libraries/System.Net.Http/src/System/Net/Http/HttpClient.cs
Line 810 in ab4e593
I'm curious if it's possible to change this behavior by way of dependency injection or other options to be able to support wider or narrower scopes, rather than using this hard-coded approach.
The rest doesn't need to be modified.
This check is currently bypassed in my project by reflection, which works but does not seem elegant and efficient.
https://github.com/newbe36524/Newbe.Demo/blob/feature/blazor/src/BlogDemos/Newbe.Blazor/Newbe.Blazors.TryNet/Newbe.Blazors.TryNet/Pages/Index.cs#L67
6 remaining items
karelz commentedon May 25, 2021
@stephentoub what do you think?
newbe36524 commentedon Jun 16, 2021
Hi, friends, any update? I wonder that would it be ok in next net 6 preview or not?
wfurt commentedon Jun 16, 2021
AFIK It is too late for preview 6 @newbe36524. We agreed this may make sense but it is not on top of the priority list.
davidfowl commentedon Jun 16, 2021
Would a pull request be accepted?
karelz commentedon Jun 16, 2021
Yes, we would take a PR.
@stephentoub do you have opinion on the plan?
stephentoub commentedon Jun 16, 2021
As long as all of our handlers do the appropriate validation for what they're capable of, removing such validation from HttpClient / HttpRequestMessage sounds like the right thing to do.