How to Load Unity WebGL Build Locally in a Chrome Extension?

107 views
Skip to first unread message

Awais iqbal

unread,
Nov 18, 2024, 1:16:37 PM11/18/24
to Chromium Extensions

Hi,

I’m building a Chrome extension that integrates a Unity WebGL build. Instead of hosting the WebGL files remotely, I want to keep them within the extension's assets for faster loading and offline access.

I’ve added the WebGL files (.loader.js, .framework.js, .data, .wasm) to the extension and am using an iframe to load an HTML file that initializes Unity. However, the Unity loader throws errors when trying to fetch the .data and .wasm files, likely due to Chrome’s security policies.

How can I configure my extension to load these files locally? Are there specific manifest.json settings or paths I need to use?

Thanks in advance!

Sebastian Benz

unread,
Nov 18, 2024, 4:50:55 PM11/18/24
to Chromium Extensions, wess...@gmail.com
Hey Awais,

can you please share a code snippet on how you're embedding unity + the error message that you're getting? 

Thanks!

Sebastian

Awais iqbal

unread,
Nov 19, 2024, 8:20:49 AM11/19/24
to Sebastian Benz, Chromium Extensions
Hello Sebastian,
 Thank you so much for reply I have tried many things and face so much errors I am posting the current state of code and error.
Function of playing: I will pick up the sentence if mouse is hovered on sentence for 3 seconds and will use that sentence for so animation from webgl
Please see attachments of errors and let me know if you need something else.
er2.png
er1.png

Sebastian Benz

unread,
Nov 19, 2024, 8:28:33 AM11/19/24
to Chromium Extensions, wess...@gmail.com, Chromium Extensions
Thanks. Am I seeing it right that you're downloading the webgl loader from chatgpt.com? This is considered remote hosted code and is not allowed. All your Javascript files must be bundled with your extension. Checkout our remote hosted code guide to learn how to avoid this.

Awais iqbal

unread,
Nov 19, 2024, 8:40:04 AM11/19/24
to Sebastian Benz, Chromium Extensions
That is correct, because I am injecting script run time into the website. Whichever website is opened in this case it was chatgpt. How can I bundle webgl build into the extension? I have tried to open an html page in my plugin and try to load a webgl file in that page but it did not work. I am new to this and would much appreciate it if you guide me or suggest to me some documentation which will help me with chrome extension.

Sebastian Benz

unread,
Nov 19, 2024, 12:04:33 PM11/19/24
to Chromium Extensions, wess...@gmail.com, Chromium Extensions
You can load assets from your extension by declaring them as web_accessible_resources. The sample should be a good starting point.
Reply all
Reply to author
Forward
0 new messages