Reputation: 1243
I'm working on an application that is supposed to run over a custom transfer protocol which is pretty much the same as http but has a package://
prefix instead of http://
in the beginning of the query string. So a query to a resource named index.html
would look like package://resources/index.html
.
I would like to deploy a Blazor WebAssembly application into this environment. The problem is that as soon as Blazor's index.html
gets loaded - it loads blazor.webassembly.js
which uses fetch()
to load blazor.boot.json
. However, fetch()
seems to only be working with http
and https
(not sure why) and I get this error:
blazor.webassembly.js:1 Fetch API cannot load package://package_name/wwwroot/_framework/blazor.boot.json.
URL scheme "package" is not supported.
(anonymous) @ blazor.webassembly.js:1
blazor.webassembly.js:1 TypeError: Failed to fetch
at Function.<anonymous> (blazor.webassembly.js:1)
at blazor.webassembly.js:1
at Object.next (blazor.webassembly.js:1)
at blazor.webassembly.js:1
at new Promise (<anonymous>)
at blazor.webassembly.js:1
at Function.initAsync (blazor.webassembly.js:1)
at blazor.webassembly.js:1
at blazor.webassembly.js:1
at Object.next (blazor.webassembly.js:1)
I was thinking that maybe it would help to override fetch
with a function that would use XMLHttpRequest
inside but I'm not sure if that's doable in js. Overall, I'm wondering how to make Blazor work in an application that is run over a protocol that is not http
or https
but is very similar except for the scheme naming.
Upvotes: 0
Views: 771
Reputation: 2601
The short answer is it is not possible. After all, each browser is an HTTP client. While some browsers have adopted other protocols for special purposes like RTC for web conferencing, they can't support custom protocols out of the box. There might be a way to write a browser extension, that enables the usage of package://. Or you find a way to "trick" the browser into making an HTTP(s) call of URIs starting with "package://" via manipulating browser preference or OS values. But again it would require you to do it for each machine that should execute your application.
The second possible problem lies within the WASM application. If the WASM application wants to interact with another service, like an API, you would normally use a HttpClient
instance. Blazor WASM provides a handler that uses the browser fetch API
to make these calls. Because a WASM application runs in a special sandbox mode, you can't access all the system-level features like you would in a normal .NET application including (but not limited) to sockets. So, you can't implement a customer transport protocol here either.
If you still want to have a Blazor application and using your custom protocols for the "internal" communication, Blazor Server Side could be an option. There you can implement your own transport protocol (with Sockets and all .NET classes/libraries) while using standard technology to interact with the browser.
Upvotes: 2