Last active
February 6, 2017 20:11
-
-
Save Treora/150dca4b57b1b881bd049303e82c5ced to your computer and use it in GitHub Desktop.
Proof of failure of a PouchDB live changes feed in a WebExtension. Try open this in two tabs (click the browser action button twice), add some items in one, and check if the other receives the changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chrome.browserAction.onClicked.addListener(() => { | |
chrome.tabs.create({url: '/testchanges.html'}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"manifest_version": 2, | |
"name": "test pouchdb changes", | |
"version": "1.0", | |
"description": "Different tabs/processes do not receive live changes when the extension requests 'storage' permission. Try open this in two tabs (click the browser action button twice), add some items in one, and check if the other receives the changes. Fails at least in Firefox 50 and Chromium 55, with PouchDB 6.1.0.", | |
"browser_action": {}, | |
"background": { | |
"scripts": ["/background.js"] | |
}, | |
"permissions": [ | |
"storage" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const db = new PouchDB('testdb') | |
db.changes({ | |
live: true, | |
include_docs: true, | |
}).on('change', change => { | |
let text = "\n" + JSON.stringify(change.doc) | |
document.getElementById('changes').innerText += text | |
}).catch(e => { | |
console.error(e) | |
}) | |
function addItem(letter) { | |
db.put({ | |
_id: new Date().toJSON(), | |
letter: letter, | |
}) | |
} | |
document.getElementById('A').onclick = () => addItem('A') | |
document.getElementById('B').onclick = () => addItem('B') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button id="A">add A</button> | |
<button id="B">add B</button> | |
<h3>Changes:</h3> | |
<pre id="changes"></pre> | |
<script src="/pouchdb.min.js"></script> | |
<script src="test.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment