Skip to content

Instantly share code, notes, and snippets.

View dfahlander's full-sized avatar

David Fahlander dfahlander

  • Awarica AB
  • Stockholm
View GitHub Profile
// This module shall be imported from BrowserWindow's main modules. The node main thread should instead import "workaround-ipc".
// NOTE: This gist shall not be used if Electron solves issue
import Dexie from "dexie";
import { ipcRenderer } from "electron";
if ("unref" in BroadcastChannel.prototype) {
// Node's BroadcastChannel has the `unref()` method.
// Seems we got the Node- and not the DOM version of BroadcastChannel.
// Only activate this workaround when we have the Node-version of BroadcastChannel
dfahlander / workaround-ipc.ts
Created February 27, 2023 00:02
Electron 23 liveQuery workaround
// This module shall be imported from the main node module in electron.
// The BrowserWindows shall instead import 'workaround-renderer.ts'
// NOTE: This gist shall NOT be used in Electron versions where is resolved
import { ipcMain } from "electron";
import { BrowserWindow } from "electron";
if (typeof BroadcastChannel !== "undefined") {
// We're on electron version 23 with BroadcastChannel support in node
ipcMain.on("dexie-storagemutated", (event, json) => {
dfahlander / 1.include-dexie-export-import.js
Last active January 6, 2023 11:38
// On any web page that stores things in IndexedDB,
// open devtools and in the console, write the following:
script1 = document.createElement('script');
script1.src = '';
script2 = document.createElement('script');
script2.src = '';
dfahlander / OldFriendsComponent.jsx
Last active January 28, 2021 09:34
Example of a React component using useLiveQuery()
function FriendsComponent({minAge = 75}) {
const friends = useLiveQuery(
() => db.friends
return friends && <ul>{ =>
<li key={}>
dfahlander / observe-old-friends.js
Last active December 13, 2020 15:53
Example of how Dexie's new liveQuery() function works
import Dexie, { liveQuery } from "dexie";
const db = new Dexie('MyDatabase');
friends: '++id, name, age'
const friendsObservable = liveQuery (
() => db.friends
dfahlander / index.html
Created September 21, 2016 13:20
Testing Native Promise compatibility with indexedDB
<script src=""></script>
const log = txt => console.log(txt);//document.writeln(`${txt}<br/>`);
log (`Hello world!`);
let db = new Dexie ('db');
friends: '++id,name,age'
dfahlander / index.html
Created September 19, 2016 20:41
Naildown of webkit bug #158833
const log = txt => document.writeln(`${txt}<br/>`);
log("Deleting db2");
indexedDB.deleteDatabase("db2").onsuccess = ()=> {
log("db2 deleted");
let req ="db2", 1);
req.onupgradeneeded = e => {
log ("Creating db2");
let db = req.transaction.db;
dfahlander / index.html
Last active September 17, 2016 19:29
Test test test
document.writeln("Hello world!");
dfahlander /
Last active September 22, 2016 22:33
Repro of IndexedDB bug in Safari10 (webkit bug #158833)

IndexedDB Safari10 bug (webkit bugzilla #158833)

IDBIndex is unreliable on Safari 10

Basically, if you have objectStores 'students' with an index 'name' and 'schools' with an index 'city', and you query the 'name' index on 'students' with no range specified (or WITH a range - it doesnt matter), you will get a cursor that iterates a mix of student names and cities. Each onsuccess callback from the cursor will have a key that sometimes is a student name and sometimes a city. The value though is always a student and some students are shown multiple times - one time with the name key and another time with a city key.

Bugzilla URL

dfahlander /
Last active August 22, 2016 15:41 — forked from nolanlawson/
Safari IndexedDB/WebSQL bug wishlist

Safari IndexedDB/WebSQL bug wishlist

Big overview of what's missing in Safari 7.1+ and iOS 8+ in terms of browser storage.

Updated May 25th 2016

Safari (general)