Can not perform this operation before game start

I’ve been following the demo on the site for Facebook Instant, but I can’t seem to get the basics working. It all works on Facebook’s side, and I have localhost testing setup correct as per Facebook’s guidelines (with openssl).

Here’s my stripped down code:

function create() {
    this.facebook.once('startgame', function() {
        console.log('Started')
    }, this)
    this.facebook.gameStarted();
}

FBInstant.initializeAsync()
    .then(function () {
        new Phaser.Game({
            type: Phaser.AUTO,
            width: window.innerWidth,
            height: window.innerHeight,
            scene: {
                create,
            }
        })
    })

The error I get in the console when loading the game in Facebook is:

{code: "INVALID_OPERATION", message: "Can not perform this operation before game start."}

Any ideas why this might be?

1 Like

I am having this same exact issue. Everything is set up according to both Facebook’s guide and the phaser official guide here http://phaser.io/tutorials/getting-started-facebook-instant-games/. Has anyone got this working and could shed some light?

It just gets stuck at 0% loading and the startgame event isn’t emitted when this.facebook.gameStarted(); is called.

I figured out the issue. It is described in the github issue here https://github.com/photonstorm/phaser/issues/4550. This error is happening because gameStarted() needs to be called after FBInstant.startGameAsync().

Here is a temporary fix:

function create() {
    this.facebook.once('startgame', function() {
        console.log('Started')
    }, this)
    FBInstant.startGameAsync().then(this.facebook.gameStarted.bind(this));
}