Working with instant games api and playcanvas editor


How do i go about implementing the instant games api in the editor and test it ?

Currently testing it is a long process, have to download a published build and then upload it manually to facebook instant API, and once its uploaded, only then could i test api functionality. I could automate this step sure, but attaching functions to buttons is proving a bit of a headache.

The issue is not being able to test in the editor.

As the Instant Games API requires the sdk to be integrated via script markup directly from a CDN ( and not added in the project), I’ve created a script to append the HTML markup into a document.

Here is a project with my current attempt at integrating the API:

Not able to even log out a console message, what am i doing wrong or is this likely not possible to integrate within the editor?


It just doesnt seem like the html is being appended to the root of the index.html file, can anyone please comment or take a look maybe im doing something wrong?


Looks like it is added to the HTML?


This would be the way I would handle the ‘loadThisFirst’ callback. It still doesn’t work (FBInstant not defined) but the code does get executed compared to the current state:


yes ofcourse this makes much more sense, i was going with a shoddy example. thanks @yaustar will try this out


Ah, here we go. I thought the loadAPI event was fired from the FB Instant SDK but then I realised it was from the project.

Here’s the new version that no longer has the ‘FBInstant not defined’ error:


thank you again.

okay so this technically works but the current problem with this is that playcanvas will load before anything else loads, which means that the instant game loading bar will not progress until playcanvas has finished in the background, ultimately this will not pass review on facebook i fear.
it would have to be the first thing that loads before playcanvas scripts/engine.

would a Loading Screen script help with this?

something like this :

/*jshint esversion:6*/
pc.script.createLoadingScreen(function (app) {
    var showSplash = function () {
       var str =  `<script src=""></script>
        <script type="text/javascript"> 
            window.addEventListener("loadAPI", loadThisFirst);
            function loadThisFirst() {
                FBInstant.initializeAsync().then(function() {
                    // Finished loading. Start the game
                    FBInstant.startGameAsync().then(function() {

            function selectContext() {
                    .then(function() {

            function startGame() {
                // start game
                var game = new gameplayScene(FBInstant);
        var instantApiDiv = document.createElement('div'); = "fbInstantAPI";
        instantApiDiv.innerHTML = str;
        // splash wrapper
        var wrapper = document.createElement('div'); = 'application-splash-wrapper';

        // splash
        var splash = document.createElement('div'); = 'application-splash';
        wrapper.appendChild(splash); = 'none';

        var logo = document.createElement('img');
        logo.src = '';
        logo.onload = function () {
   = 'block';

        var container = document.createElement('div'); = 'progress-bar-container';

        var bar = document.createElement('div'); = 'progress-bar';


    var hideSplash = function () {
        var splash = document.getElementById('application-splash-wrapper');

    var setProgress = function (value) {
        var bar = document.getElementById('progress-bar');
        if(bar) {
            value = Math.min(1, Math.max(0, value));
   = value * 100 + '%';

    var createCss = function () {
        var css = [
            'body {',
            '    background-color: #283538;',

            '#application-splash-wrapper {',
            '    position: absolute;',
            '    top: 0;',
            '    left: 0;',
            '    height: 100%;',
            '    width: 100%;',
            '    background-color: #283538;',

            '#application-splash {',
            '    position: absolute;',
            '    top: calc(50% - 28px);',
            '    width: 264px;',
            '    left: calc(50% - 132px);',

            '#application-splash img {',
            '    width: 100%;',

            '#progress-bar-container {',
            '    margin: 20px auto 0 auto;',
            '    height: 2px;',
            '    width: 100%;',
            '    background-color: #1d292c;',

            '#progress-bar {',
            '    width: 0%;',
            '    height: 100%;',
            '    background-color: #f60;',
            '@media (max-width: 480px) {',
            '    #application-splash {',
            '        width: 170px;',
            '        left: calc(50% - 85px);',
            '    }',

        var style = document.createElement('style');
        style.type = 'text/css';
        if (style.styleSheet) {
          style.styleSheet.cssText = css;
        } else {



    app.on('preload:end', function () {'preload:progress');
    app.on('preload:progress', setProgress);
    app.on('start', hideSplash);


TBH, I think there is a different workflow needed for the FB instant games. @vaios, is it possible to use the FB Instant Games SDK from inside the PlayCanvas editor or is it a separate workflow that has to be done post build?


I think testing in the editor will not be possible for sure, so downloading the build using the playcanvas rest API, will be the best thing to do.

the loading screen script did not work, so i do think there might need to be more happening in the post build script, not sure where to begin, shell scripts or otherwise, but have to download using REST, unzip, add the API script tag in the index html, as well as adding a fbapp-config.json in the root, before zipping back up and posting to fb instant web hosting.

automating this is my current challenge. Doing less in the post-build script is proving problematic, so may have to do it all there.


I found the Phaser tutorial on creating Facebook Instant games and was actually wondering if it was possible to replace the start and preload or even just preload script to use the Facebook loading bar instead. I might give the latter a try when I get some time


I’m starting to look into FB integration myself, so am keen to find out more and help out where I can.

I wonder is it possible to upload a version of a launcher to the FB developer area, that would then launch the published game on the PlayCanvas site, and give access to the FBInstant object. In this way, you could still do quick tests and changes in the editor, publish, and then re-launch from FB to see the changes.


Hi! I’m too looking at developing instant games using playcanvas. Is there any resource on how to implement the instant games loader for a playcanvas project?



I see what youre saying, it could just be an iframe that you upload to fb webhost, and this points to your playcanvas launch URL.

ill test and report back

looks like iframe will work with published build but not editor launch URL, can playcanvas team comment on this? is there a way round to using iframe in launch URL for testing purposes, and if not, can the published build be unlisted?