C2Runtime:Unhandled security exception around indexedDB.open

0 favourites
  • 2 posts
From the Asset Store
Find and Destroy all computer malware in this lighthearted security game.
  • Problem Description

    On iPad.iOS9, the call to indexedDB.open("_C2SaveStates"); creates a security exception when a C2 project is embeded in an iFrame that has different domain than its top parent container.

    In order for the IndexedDB_WriteSlot and IndexedDB_ReadSlot to properly handle the security exception and fallback from indexedDB to localStorage, the 2 functions IndexedDB_WriteSlot and IndexedDB_ReadSlot must properly handle the security exception by adding a try/catch block as below:

    function IndexedDB_WriteSlot(slot_, data_, oncomplete_, onerror_)

    {

    try{

    var request = indexedDB.open("_C2SaveStates");

    request.onupgradeneeded = makeSaveDb;

    request.onerror = onerror_;

    request.onsuccess = function (e)

    {

    var db = e.target.result;

    db.onerror = onerror_;

    var transaction = db.transaction(["saves"], "readwrite");

    var objectStore = transaction.objectStore("saves");

    var putReq = objectStore.put({"slot": slot_, "data": data_ });

    putReq.onsuccess = oncomplete_;

    };

    }catch (err){

    onerror_(err);

    }

    };

    function IndexedDB_ReadSlot(slot_, oncomplete_, onerror_)

    {

    try{

    var request = indexedDB.open("_C2SaveStates");

    request.onupgradeneeded = makeSaveDb;

    request.onerror = onerror_;

    request.onsuccess = function (e)

    {

    var db = e.target.result;

    db.onerror = onerror_;

    var transaction = db.transaction(["saves"]);

    var objectStore = transaction.objectStore("saves");

    var readReq = objectStore.get(slot_);

    readReq.onsuccess = function (e)

    {

    if (readReq.result)

    oncomplete_(readReq.result["data"]);

    else

    oncomplete_(null);

    };

    };

    }catch (err){

    onerror_(err);

    }

    };

    Attach a Capx

    ____ Upload a Capx to this post ____

    Description of Capx

    ____ Concise description of what this CapX does ____

    Steps to Reproduce Bug

      Create a frameset and publish on a.domain.com in the frameset create an iframe and point its source to C2 project on b.toolwire.com/index.html in the C2 project, create a button, and on click use system -> Save to save the game state

    Observed Result

    on iPad, at every tick, the Runtime.prototype.handleSaveLoad = function () which does not handle the security exception raised by IndexedDB_WriteSlot()

    Expected Result

    ____ What do you expect to happen? ____

    Affected Browsers

    • Chrome: (YES/NO)
    • Safari: (YES/NO)

    Operating System and Service Pack

    iPad iOS 9, android

    Construct 2 Version ID

    all versions v2.06, v2.12, v2.16

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Fixed for the next build.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)