Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

167
Vistas
Replacing window.localStorage implementation for Facebook Instant Games

I am preparing a game for publishing at Facebook Instant Games.

My game uses Pixi.js and jQuery UI - and saves some user settings like "color theme" and "sound volume" in window.localStorage:

game screenshot

However when trying to access it from my Instant Game, I get the error:

DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.

I guess the root cause is that Facebook Instant games run in an iframe.

However, I have already published my game at the Yandex Games platform and there they offer a replacement for localStorage by running the following code:

ysdk.getStorage()
    .then(safeStorage => Object.defineProperty(window, 'localStorage', 
        { get: () => safeStorage }))
    .then(() => {
       localStorage.setItem('key', 'safe storage is working');
       console.log(localStorage.getItem('key'))
    });

So I wonder if the same trick is possible by using FBInstant.player.setDataAsync() and FBInstant.player.getDataAsync() found in the Instant Games SDK?

I have tried:

Object.defineProperty(window, 'localStorage', 
    { get: () => { 
    getItem: { FBInstant.player.getDataAsync() }, 
    setItem: { FBInstant.player.setDataAsync() } } }));

but that is of course not working... I am not even sure, how to deal with Facebook's async functions here.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You would need to keep the syntax

Object.defineProperty(window, 'localStorage', 
{ getItem: key => FBInstant.player.getDataAsync(...) , 
  setItem: (key,str) => FBInstant.player.setDataAsync(...)
})

https://developers.facebook.com/docs/games/instant-games/sdk/fbinstant6.1/

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda