Skip to content

Instantly share code, notes, and snippets.

@Treora
Last active February 6, 2017 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Treora/150dca4b57b1b881bd049303e82c5ced to your computer and use it in GitHub Desktop.
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.
chrome.browserAction.onClicked.addListener(() => {
chrome.tabs.create({url: '/testchanges.html'})
})
{
"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"
]
}
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')
<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