Zeronet: I make a WebGl game based on Unity3d. Then I put these files under my websites folder (clear all original files). When I open my web through ZeroNet, it just show nothing.

Created on 10 Jan 2018  路  13Comments  路  Source: HelloZeroNet/ZeroNet

Step 1: Please describe your environment

  • ZeroNet version: 0.60(3178)
  • Operating system: Windows64
  • Web browser: firefox
  • Tor status: not available
  • Opened port: no
  • Special configuration: no

Step 2: Describe the problem:

Steps to reproduce:

just replace the web files using webgl-based game files.

Observed Results:

It just shows nothing but a "0" symbol in left, when i open it through websites.
when i open the log of javascript, i see this "cause锛欳ORS head miss 'Access-Control-Allow-Origin'"

Expected Results:

the web should be a web-game. When i open it by clicking the index.html, it can work.(the prefix of url is file://, not https://). However, when i open it through ZeroNet, it can not work. (the prefix of url is http://,)

Most helpful comment

Fixed: 1FevQJGEw5XadC1Hmkc6fL3WJcqyUmkXay.zip

When you are transfering ClearNet site to ZeroNet, you can't just copy files. For example:

  1. In ZeroNet you must use localStorage via ZeroFrame API only.
  2. You can't simply use XHR or fetch.
  3. You must add <base> and a script to <head>.
  4. And many more. You can find some of them in my tutorial.

So I've added a monkey-patch to make XHR work and included ZeroFrame to your site.

All 13 comments

Please, provide the address of your site.

@tangdou1 Did you sign that? Also, if I could not download that site you could just send a ZIP here.

@imachug Thanks for your attention. Here is the file

webgl-game.zip

Okay I can reproduce the problem.

Fixed: 1FevQJGEw5XadC1Hmkc6fL3WJcqyUmkXay.zip

When you are transfering ClearNet site to ZeroNet, you can't just copy files. For example:

  1. In ZeroNet you must use localStorage via ZeroFrame API only.
  2. You can't simply use XHR or fetch.
  3. You must add <base> and a script to <head>.
  4. And many more. You can find some of them in my tutorial.

So I've added a monkey-patch to make XHR work and included ZeroFrame to your site.

@imachug Thank you very much. It indeed works now.

@tangdou1 @HelloZeroNet I assume this can be closed now?

@imachug Can you help me?

<!DOCTYPE html>
<html lang="en-us">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Unity WebGL Player | UnitZUNET</title>
    <link rel="shortcut icon" href="TemplateData/favicon.ico">
    <link rel="stylesheet" href="TemplateData/style.css">
    <script src="TemplateData/UnityProgress.js"></script>  
    <script src="Build/UnityLoader.js"></script>
    <!-- <script> -->
      <!-- var gameInstance = UnityLoader.instantiate("gameContainer", "Build/1.json", {onProgress: UnityProgress}); -->
    <!-- </script> -->
   <script src="js/ZeroFrame.js"></script>
    <script>
      var page = new ZeroFrame();

      // Monkey-patch
      XMLHttpRequest.prototype.realOpen = XMLHttpRequest.prototype.open;
      page.cmd("wrapperGetAjaxKey", [], function(ajax_key) {
        var newOpen = function(method, url, async) {
            url += "?ajax_key=" + ajax_key;
            if(typeof async == "undefined") {
              return this.realOpen(method, url);
            } else {
              return this.realOpen(method, url, async);
            }
        }
        XMLHttpRequest.prototype.open = newOpen;

        var gameInstance = UnityLoader.instantiate("gameContainer", "Build/1.json", {onProgress: UnityProgress});
      });
    </script>
  </head>
  <body>
    <div class="webgl-content">
      <div id="gameContainer" style="width: 960px; height: 600px"></div>
      <div class="footer">
        <div class="webgl-logo"></div>
        <div class="fullscreen" onclick="gameInstance.SetFullscreen(1)"></div>
        <div class="title">UnitZUNET</div>
      </div>
    </div>
  </body>
</html>

This <div class="fullscreen" onclick="gameInstance.SetFullscreen(1)"></div> can not work, because the variable gameInstance is a local variable now.

change var gameInstance = to window.gameInstance = should change it to global

@tangdou1 What @HelloZeroNet should work, but if you use Unity's own SetFullscreen method, it probably won't work in ZeroNet, you need to use ZeroFrame API. If you encounter this error, you should send me a new ZIP, so I could implement fullscreen.

@imachug @HelloZeroNet Thanks, it can work now by changing var gameInstance = to window.gameInstance =

Now zites can run without iFrame limitations.
Reference: #1262

Fixed: 1FevQJGEw5XadC1Hmkc6fL3WJcqyUmkXay.zip

When you are transfering ClearNet site to ZeroNet, you can't just copy files. For example:

  1. In ZeroNet you must use localStorage via ZeroFrame API only.
  2. You can't simply use XHR or fetch.
  3. You must add <base> and a script to <head>.
  4. And many more. You can find some of them in my tutorial.

So I've added a monkey-patch to make XHR work and included ZeroFrame to your site.

hello I made this Zite and I have some errors, I need your help to fix them. this is an example of a unity WebGl game.
1BkyaBHKaAkc9pNSFGQrTaubj6eH5ADHod

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BenMcLean picture BenMcLean  路  3Comments

yurkobb picture yurkobb  路  3Comments

wigy-opensource-developer picture wigy-opensource-developer  路  4Comments

blurHY picture blurHY  路  3Comments

trenta3 picture trenta3  路  3Comments