Chrome 开发工具之 Application
{ "name": "testApp", "short_name": "tApp", "display": "fullscreen", "background_color": "#000", "start_url": "/", "description": "A test web app for manifest", "icons": [ { "src": "https://developers.google.com/web/images/web-fundamentals-icon192x192.png", "type": "image/png", "sizes": "192x192" } ] }
if (\'serviceWorker\' in navigator) { const sw = navigator.serviceWorker .register(\'/testhtml/sw.js\', { scope: \'/testhtml/\' }) .then(function(reg) { if (reg.installing) { console.log(\'Service worker installing\') } else if (reg.waiting) { console.log(\'Service worker installed\') } else if (reg.active) { console.log(\'Service worker active\') } reg.update() }) .catch(function(error) { console.log(\'Registration failed with \' + error) }) navigator.serviceWorker.ready.then(sw => { return sw.sync.register(\'hello-sync\') }) navigator.serviceWorker.ready.then(async sw => { const bgFetch = await sw.backgroundFetch.fetch(\'custom-fetch\', [\'1.jpg\'], { title: \'download 1.jpg\', icons: [ { sizes: \'300x300\', src: \'2.jpg\', type: \'image/jpg\' } ] }) }) }
self.addEventListener(\'install\', event => { event.waitUntil( caches.open(\'v1\').then(cache => { return cache.addAll([ \'/testhtml/test.html\', \'/testhtml/test.css\', \'/testhtml/test.js\', \'/testhtml/2.jpg\' ]) }) ) }) self.addEventListener(\'sync\', event => { if (event.tag == \'hello-sync\') { console.log(\'receive hello-sync\') } }) self.addEventListener(\'fetch\', event => { event.respondWith( caches.match(event.request).then(response => { if (response !== undefined) { return response } else { return fetch(event.request) .then(response => { let responseClone = response.clone() caches.open(\'cache_1\').then(cache => { cache.put(event.request, responseClone) }) return response }) .catch(() => {}) } }) ) })
- 卸载 services workers
- Local storage 和 Session storage
- IndexedDB 数据
- Web SQL 数据
- Cookies
- Cache storage
- 图中底下还有 Application Cache 的选项未能截全…
localStorage.setItem(\'astring\', \'This is an apple\') localStorage.setItem(\'aobject\', { say: \'hello\' }) localStorage.setItem(\'aboolean\', false)
const IDBOpenDBRequest = indexedDB.open(\'testDB\', 1) IDBOpenDBRequest.onsuccess = e => { const db = IDBOpenDBRequest.result const transaction = db.transaction([\'User\', \'Book\'], \'readwrite\') const objStore = transaction.objectStore(\'User\') const objBookStore = transaction.objectStore(\'Book\') // User 表加2条数据 objStore.put({ name: \'xiaoming\', age: 18, sex: 1 }) objStore.put({ name: \'xiaohong\', age: 18, sex: 2 }) // Book 表加一条数据 objBookStore.put({ bookName: \'< hello world >\', price: 29, status: 1 }) } IDBOpenDBRequest.onupgradeneeded = e => { const db = IDBOpenDBRequest.result const store = db.createObjectStore(\'User\', { keyPath: \'name\' }) store.createIndex(\'name\', \'name\') store.createIndex(\'age\', \'age\') store.createIndex(\'sex\', \'sex\') const bookStore = db.createObjectStore(\'Book\', { keyPath: \'id\', autoIncrement: true }) bookStore.createIndex(\'bookName\', \'bookName\') bookStore.createIndex(\'price\', \'price\') bookStore.createIndex(\'status\', \'status\') }
add_header Set-Cookie "say=hello;Domain=local.tuya-inc.cn;Path=/;Max-Age=10000";