Skip to content

Instantly share code, notes, and snippets.

@jsantell
Created March 27, 2013 17:17
Show Gist options
  • Save jsantell/5256189 to your computer and use it in GitHub Desktop.
Save jsantell/5256189 to your computer and use it in GitHub Desktop.
Jetpack page-mod/bfcache
/*
* testing page-mod's persistence with bfcache
*/
require('sdk/page-mod').PageMod({
include: '*',
contentScript: 'new ' + fn
});
// Content script
function fn () {
var count = 0;
console.log("load: " + document.location.href);
setInterval(function () {
++count;
console.log("ping " + count + ": " + document.location.href);
}, 3000);
}
/*
Output: Loading `products` page, then clicking on `about`,
going "back" to `products` and then "forward" to `about`,
persisting counts and pings without reloading
info: pagemod: load: http://www.mozilla.org/en-US/products/
info: pagemod: ping 1: http://www.mozilla.org/en-US/products/
info: pagemod: ping 2: http://www.mozilla.org/en-US/products/
info: pagemod: ping 3: http://www.mozilla.org/en-US/products/
info: pagemod: load: http://www.mozilla.org/en-US/about/
info: pagemod: ping 1: http://www.mozilla.org/en-US/about/
info: pagemod: ping 2: http://www.mozilla.org/en-US/about/
info: pagemod: ping 3: http://www.mozilla.org/en-US/about/
info: pagemod: ping 4: http://www.mozilla.org/en-US/products/
info: pagemod: ping 5: http://www.mozilla.org/en-US/products/
info: pagemod: ping 6: http://www.mozilla.org/en-US/products/
info: pagemod: ping 4: http://www.mozilla.org/en-US/about/
info: pagemod: ping 5: http://www.mozilla.org/en-US/about/
info: pagemod: ping 6: http://www.mozilla.org/en-US/about/
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment