C2Runtime:Unhandled security exception around indexedDB.open

Bugs will be moved here once resolved.

Post » Fri Nov 20, 2015 7:02 pm

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
B
5
S
1
Posts: 10
Reputation: 419

Post » Tue Nov 24, 2015 3:42 pm

Fixed for the next build.
Scirra Founder
B
384
S
227
G
86
Posts: 24,139
Reputation: 190,761


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 0 guests