Extension to interact with the web in exported games

Let’s start with the demo: an exported Arcade game that opens a new browser tab.

In general, Arcade games are completely sandboxed… So how can we open a new tab? Let’s take a look.

The control.simmessages is a new API added in Arcade to support the JACDAC simulator… but you can use it too in GitHub Pages.

simmessages allow to send or receive a data payload to the hosting iframe of the simulator (those messages are ignored on hardware). In arcade.makecode.com, you are not allowed to inject custom javascript to handle those messages BUT… if you export your game to GitHub, you put your custom logic and do all kinds of cool features.

In this demo, the game calls a “open url” function

That function sends a “web open url” message over control.simmessages.

On the browser javascript side, we’ve added custom code to handle the message.

and we’ve registered a function handler for the “web” channel

So eventually, through a few layers your message from the MakeCode Arcade game routes itself to the handler that calls window.open.

Full sources https://github.com/pelikhan/arcade-browser

4 Likes

Nice! I can see use in like if you have a really complex game, instead of explaining it all in text boxes you can redirect them to your README.md in the repository.

Except, it doesn’t work for me:

1 Like

Indeed, i broke it !

1 Like

Fixed in v.0.0.4. Thanks!

1 Like

Nice, it works!

The first 2 times, it didn’t work because Chrome considered it a “pop-up”. The third time worked. Just saying if anyone is confused.

Hello! Is the code still working? I have tried to implement it in my game but it opens a new simulator instead of redirecting to an URL. Could you kindly help me out? Thanks a lot!