uniqueKeys() fails in Safari on empty DB
Unhandled rejection: UnknownError: Unable to open cursor
Add a row: it works.
Ok, thanks! We'd need a repro to verify this. Seems it would be easy to patch it in dexie. There still seems to be a few issues with Safari we'll need to patch.
For any voluntary user: A repro of this issue should be placed in a new unit test, in any of the existing modules such as tests-misc.js.
It would be important to know what actually triggers the error. Possible reasons:
- Database is empty
- Table is empty
- No read- or write requests where made to the database since current connection was opened.
- No write requests has been made since current connection was opened.
Also, this issue should be filed in Webkit bugzilla
This is a dup of #1030. Repro is available in #1030.
Still happening
I can't reproduce this in Safari Version 17.3.1 (19617.2.4.11.12). Repro link: https://jsfiddle.net/dfahlander/6rqyfag9/. @AlejandroAkbal Could you run the repro? What version of Safari do you use?
Tried with Browserstack on Safari Version 15.6.1 (17613.3.9.1.16). The repro isn't hit there either. Output:
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15
Dexie: 3.2.6
Could NOT reproduce the issue on this browser
I continued downgrading browser and had to go all the way down to Safari 13 to make the repro hit the bug: Safar Version 13.1.2 (15609.3.5.1.3).
Output:
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15
Dexie: 3.2.6
Issue Reproduced! UnknownError: Unable to open cursor
UnknownError: Unable to open cursor
Closing as the bug seem to be solved since Safari 14 (2020).
I got the same error in Safari 17.6 (Mac OS Sonoma 14.6.1)
I got the same error in Safari 17.6 (Mac OS Sonoma 14.6.1)
Thanks. Does it reproduce with this repro? If not, could you supply a repro for the case where it fails on Safari 17.6, Mac OS Sonoma 14.6.1.
Yes
Hi!
I've been integrating Dexie to use as a long duration cache and during testing we also noticed this bug. There seems to a difference on how Safari handles uniqueKeys on empty tables compared other browser.
I'm using uniqueKeys to make sure we don't store an excessive amount of data in some of our tables as they quickly can reach thousands of rows per unique key, and cleanup any excess and stale data if necessary. Our current workaround is simply checking if the table is empty, and skip cleanup based on uniqueKeys if it is.
This was tested on OSX 10.15.7 and Safari 17.3.
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.3 Safari/605.1.15
Dexie: 4.0.9
UnknownError: Unable to open cursor
The following code reproduces this as of latest Dexie 4.0.9 version:
<!DOCTYPE html>
<html>
<!-- Include dexie.js -->
<script src="https://npmcdn.com/dexie/dist/dexie.js"></script>
<!-- Just a simple log function... -->
<script>
function log(txt) {
document.getElementById("log").value += txt + "\n";
}
// Check that browser supports generator functions:
try {
eval("(function* (){})");
} catch (e) {
log(
"This browser doesn't support generator functions. Must use a recent version of Chrome, Opera, Firefox or Edge."
);
}
</script>
<style>
body {
font-family: Arial;
padding: 10px;
}
textarea {
width: 100%;
height: 50vh;
}
</style>
<body>
<!-- Some HTML for the log window -->
<a href="http://dexie.org/docs/API-Reference" target="_new"
>Dexie API Reference (new tab)</a
>
<h3>Log</h3>
<textarea id="log"></textarea>
<p id="safari-version" style="display: none">
This browser denies indexedDB access from iframes.
<a href="https://fiddle.jshell.net/dfahlander/6rqyfag9/show" target="_top"
>Click here to open it directly without any iframe.</a
>
</p>
</body>
<script defer>
var db = new Dexie("MyFriendDB3");
db.version(1).stores({
consumption: "a, b",
});
async function main() {
log("User agent: " + navigator.userAgent);
log("Dexie: " + Dexie.semVer);
try {
const uniqueKeys = await db.consumption.orderBy("a").uniqueKeys();
log("Unique keys: " + JSON.stringify(uniqueKeys));
} catch (error) {
log(error);
}
await db.delete();
}
main().catch((e) => {
if (e.inner) e = e.inner;
if (e.name === "MissingAPIError") log("Couldn't find indexedDB API");
else if (e.name == "SecurityError") {
document.getElementById("log").style = "display:none";
document.getElementById("safari-version").style = "display:";
} else {
log(e);
}
});
</script>
</html>
I'm not able to reproduce it with Lambdatest or on my own Safari browser but I believe you of course. Just interesting to understand the circumstances where it fails. If I could it would be easier to build a workaround in dexie and test it.
In your reports, the issue should be present in:
- Safari 17.6 (Mac OS Sonoma 14.6.1)
- Safari 17.3 (OSX 10.15.7)
But I cant reproduce it on any device in neither browserstack och lambdatest or on my laptop except on Safari 13 with Mac OS Catalina on Browserstack.
I'll reopen the issue and plan to do a workaround for this i dexie. If anyone finds some other circumstances that makes this repro succeed to reproduce the issue on a modern Safari, let me know.
I'm not able to reproduce it with Lambdatest or on my own Safari browser but I believe you of course. Just interesting to understand the circumstances where it fails. If I could it would be easier to build a workaround in dexie and test it.
In your reports, the issue should be present in:
- Safari 17.6 (Mac OS Sonoma 14.6.1)
- Safari 17.3 (OSX 10.15.7)
But I cant reproduce it on any device in neither browserstack och lambdatest or on my laptop except on Safari 13 with Mac OS Catalina on Browserstack.
I'll reopen the issue and plan to do a workaround for this i dexie. If anyone finds some other circumstances that makes this repro succeed to reproduce the issue on a modern Safari, let me know.
The weird part is that the same tester tried the jsfiddle and couldn't reproduce it. But when creating that simple html file and loading it in Safari he got the bug. Gotta love edge-case issues 😄
The weird part is that the same tester tried the jsfiddle and couldn't reproduce it. But when creating that simple html file and loading it in Safari he got the bug. Gotta love edge-case issues 😄
Wow, thanks for that! I published the repro on https://dexie.org/test/dexie-issue-1052/repro-for-1052.html and could immediately reproduce it on my latest Safari Version 18.0.1 (19619.1.26.111.11, 19619) on Sonoma 14.6.1 (23G93).
In your reports, the issue should be present in: