Skip to content

Support to request extensions://** by HttpClient #52836

Closed

Description

@newbe36524

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.

Activity

  1. javiercn commented on May 17, 2021

    @javiercn
    Member

    @newbe36524 thanks for contacting us.

    This is a question for the dotnet/runtime folks

  2. transferred this issue fromdotnet/aspnetcoreon May 17, 2021
  3. ghost added
    untriaged
    on May 17, 2021
  4. karelz commented on May 17, 2021

    @karelz
    Member

    @newbe36524 what is "extensions://* protocol"? I never heard of that. What does it do? What's the protocol?

    As the exception says, HttpClient does not support it -- even Uri does not support it.
    Is it something that JavaScript / WebAssembly natively support? If yes, then it would be feature request for .NET WebAssembly I assume ...

  5. added
    arch-wasm
    on May 17, 2021
  6. newbe36524 commented on May 17, 2021

    @newbe36524
    Author

    @newbe36524 what is "extensions://* protocol"? I never heard of that. What does it do? What's the protocol?

    As the exception says, HttpClient does not support it -- even Uri does not support it.
    Is it something that JavaScript / WebAssembly natively support? If yes, then it would be feature request for .NET WebAssembly I assume ...

    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

    image

  7. newbe36524 commented on May 17, 2021

    @newbe36524
    Author

    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

  8. karelz commented on May 17, 2021

    @karelz
    Member

    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 HttpClient in WebAssembly might want to support or not.

  9. newbe36524 commented on May 17, 2021

    @newbe36524
    Author

    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 HttpClient in WebAssembly might want to support or not.

    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
    image

    click any one of backgroud page of a extensions
    image

    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://*
    image
    image

    For MS Edge, They are some files place at C:\Users[User]\AppData\Local\Microsoft\Edge\User Data\Default\Extensions[ExtenstionId][version]

  10. BenLampson commented on May 17, 2021

    @BenLampson

    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 HttpClient in WebAssembly might want to support or not.

    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:\.....

  11. wfurt commented on May 19, 2021

    @wfurt
    Member

    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.

  12. newbe36524 commented on May 20, 2021

    @newbe36524
    Author

    @wfurt In fact now, I am limited by this line of code because its requirements must be within the given range.

    if (!HttpUtilities.IsHttpUri(baseAddress))

    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

  13. 6 remaining items

  14. added this to the 6.0.0 milestone on May 25, 2021
  15. added
    enhancement
    and removed
    arch-wasm
    untriaged
    on May 25, 2021
  16. karelz commented on May 25, 2021

    @karelz
    Member

    @stephentoub what do you think?

  17. newbe36524 commented on Jun 16, 2021

    @newbe36524
    Author

    Hi, friends, any update? I wonder that would it be ok in next net 6 preview or not?

  18. wfurt commented on Jun 16, 2021

    @wfurt
    Member

    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.

  19. davidfowl commented on Jun 16, 2021

    @davidfowl
    Member

    Would a pull request be accepted?

  20. karelz commented on Jun 16, 2021

    @karelz
    Member

    Yes, we would take a PR.

    @stephentoub do you have opinion on the plan?

  21. stephentoub commented on Jun 16, 2021

    @stephentoub
    Member

    @stephentoub do you have opinion on the plan?

    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.

  22. ghost added
    in-pr
    on Jul 1, 2021
  23. ghost removed
    in-pr
    on Jul 10, 2021
  24. ghost locked as resolved and limited conversation to collaborators on Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Netenhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions