2

I've spent a LOT of time working to get a blazor plugin working, where my app is used as a plugin/embed in another domain's webpage. It's working, but the method has some serious drawbacks and I'm hoping someone has found a better way.

Just to clarify what I'm doing, my site is on the right and the code another site would need to call my plugin is on the left.

Calling Blazor as a plugin from another domain

My current method:

  1. Compile my app with Ahead Of Time compilation (AOT), as detailed here. Without this, Blazor tries to load all the dll's from the client domain instead of from my server.
  2. Add "autostart=false" and the "Blazor.start({..." code to the code the client domain's need to write on their side. This is needed b/c even with the AOT, Blazor still tries to load blazor.boot.js from the client's domain. It's hard-wired, see this issue. The issue is closed b/c they say it's fixed with JS initializers, but even with AOT, JS initializers still default to the hosting client's domain. So it's not really fixed.

The problems are:

  1. AOT is only possible with a release build. I need to do dev builds for debugging. MS has said they're working this, so probably not a blocker.
  2. The Blazor.start code on the client side looks bad.
  3. Most of Blazor's calls still defaults to using the hosting client's domain, such as the JS initializers in #2 above. Even though an empty plugin is working, I suspect that problem will prevent creating a more complex application. This is the BIG PROBLEM, and what I'm hoping someone can help with. Embedding a Blazor app in another domain can be done, but probably only for very basic Blazor pages, nothing complex.

One possible solution is MS's plan for circumventing firewall's blocking Blazor's calls to its DLL's, detailed here. This is so complex and high-maintenance I fear it would create many more problems, although I plan to give it a try anyway.

Any improvements/alternatives would be greatly appreciated! Thanks!

edit: A potential solution to most problems above would be changing the default origin used by blazor's fetch function. That doesn't really answer this question so I've created a 2nd question to cover it here.

Jason
  • 396
  • 1
  • 3
  • 17
  • This is something I will need to tackle soon, so I will watch this thread closely. In the DotnetConf, I remember them showing how easy it will be to be used inside another site(Think it was React), without using IFrames. Here I found the video (dotnetConf 2021) https://youtu.be/oPyTZ-HGdn4?t=9228 – Shuryno Dec 06 '21 at 14:21

1 Answers1

-1

There may be something in this persons blog that is usable in your situation. I'm embarking on this task myself.

John S
  • 7,909
  • 21
  • 77
  • 145