UNPKG

@readium/navigator

Version:

Next generation SDK for publications in Web Apps

66 lines (58 loc) 2.16 kB
// Note: we aren't blocking some of the events right now to try and be as nonintrusive as possible. // For a more comprehensive implementation, see https://github.com/hackademix/noscript/blob/3a83c0e4a506f175e38b0342dad50cdca3eae836/src/content/syncFetchPolicy.js#L142 // The snippet of code at the beginning of this source is an attempt at defence against JS using persistent storage (function() { const noop = () => {}, emptyObj = {}, emptyPromise = () => Promise.resolve(void 0), fakeStorage = { getItem: noop, setItem: noop, removeItem: noop, clear: noop, key: noop, length: 0 }; ["localStorage", "sessionStorage"].forEach((e) => Object.defineProperty(window, e, { get: () => fakeStorage, configurable: !0 })); Object.defineProperty(document, "cookie", { get: () => "", set: noop, configurable: !0 }); Object.defineProperty(window, "indexedDB", { get: () => {}, configurable: !0 }); Object.defineProperty(window, "caches", { get: () => emptyObj, configurable: !0 }); Object.defineProperty(navigator, "storage", { get: () => ({ persist: emptyPromise, persisted: emptyPromise, estimate: () => Promise.resolve({quota: 0, usage: 0}) }), configurable: !0 }); Object.defineProperty(navigator, "serviceWorker", { get: () => ({ register: emptyPromise, getRegistration: emptyPromise, ready: emptyPromise() }), configurable: !0 }); window._readium_blockedEvents = []; window._readium_blockEvents = true; window._readium_eventBlocker = (e) => { if(!window._readium_blockEvents) return; e.preventDefault(); e.stopImmediatePropagation(); _readium_blockedEvents.push([ 1, e, e.currentTarget || e.target ]); }; window.addEventListener("DOMContentLoaded", window._readium_eventBlocker, true); window.addEventListener("load", window._readium_eventBlocker, true); })();