WebGL: ReferenceError: UnityObject2 is not defined

I try to load the index.html with the webGL build from our project. But it stops with the first screen and this error message appears:

Yes, there is no UnityObject2 defined in the index.html, because it isn’t needed. I used the standard Unity WebGL Template.

The only communication is from the UnityScene to the Html-File to open a url in a new tab.

void OpenURL () {
  Application.ExternalCall("OpenNewTab", url);
}
<script type="text/javascript">
  function OpenNewTab(url) {
     window.open(url, "_new");
  }
</script>

As Webplayer Build it works fine.

Which objects generate the UnityObject2 request? How can i get closer to a solution?

(Unity 5.1.1.f1, Firefox 39.0)

UnityObject2 is related to the WebPlayer, and not to WebGL.

Are you getting a longer trace of where the issue is coming from ? try to look in the JS console of your browser.
Also, there’s another possibility that your c# code is “injecting” custom JS code at runtime.

You can try to look for unityobject2 in all of your project source files, maybe something will turn up that is adding it (we also used something similar in the past, so it’s not so far fetched).

1 Like

Thank you. It was a 3rd party plugin, which i can’t rember. So the hint to look in the project source files was the right one.
Shame on me. :smile:

1 Like

Don’t be so hard on yourself :slight_smile:

Hi @quaigon

Sorry to ask something a little different from the thread, but when you use that OpenNewTab method, does the browser block the popup?
I use chrome and your technique and the popup is blocked unless I add exception.
I trigger the Application.ExternalCall(“OpenNewTab”, url); in a unity UI with Pointer Down event response.

Thank you for advance!

Hey,
in this project, the html handling isn’t my job. but yes, we have the same behaviour with google chrome. but at the moment, our UnityPlayer is on a popup window. so the user has to unblocked it anyway. but good to know that there will be a problem, when we integrate the 3d-window in the webpage. i have to ask the web-developer for a solution.

1 Like

Thank you for your reply. Did the developer find a solution?