I have a game that works on Facebook Instant. I’d like to release it on web outside the Facebook Instant eco system keeping the same code base.
When I call:
fbinstant.initialize( on_intialize )
This message is shown in the browser console:
FBInstant inited undefined
But the callback (on_initialize) is never triggered inside the game.
What’s the best way of checking if the Facebook Instant API is unavailable? It would be good to get a “success false” response from fbinstant.initialize.
fbinstant.initailize() doesn’t return anything when run outside Facebook. I can’t seem to wrap my head around the code to change it.
I’m reluctant to do this, because I’d be relying on a domain name or URL that you have no control over and which might change over time (admittedly the “Facebook” domain IS probably quite safe…)
Is that the only printout in the console?
Could it be that the function doesn’t continue since the “Module._fbinstant_inited” is undefined?
If so, you could patch that in a pull request
Yeah, that’s the only relevant printout (meaning the game doesn’t crash, and continues). I’ve tried to change the code locally with, shall we say, minimal success.
Well, the Facebook Instant Games API doesn’t provide any functionality to check if run from within a Facebook context or not. And calling fbinstant.initializeAsync() simply does nothing and never returns as far as I have been able to test. The javascript promise never resolves and no error is thrown.
I see two options:
Check the browser location and if it is not launched on Facebook you either ignore calling any FBInstant APIs or you mock all calls to them (there’s a mock.lua in the extension that can be used as a base maybe).
Bundle two different versions. One version for Facebook Instant Games using the FBInstant API and one version where the API calls are removed or mocked.