清除electron應用緩存

在菜單欄添加清除按鈕

配置清除項

const clearObj = {
  storages: ['appcache', 'filesystem', 'indexdb', 'localstorage', 'shadercache', 'websql', 'serviceworkers', 'cachestorage'],
};

工具欄

{
  label: '重載',
  accelerator: 'CmdOrCtrl+R',
  click: (item, focusedWindow) => {
    if (focusedWindow) {
      // 重載之後, 刷新並關閉所有之前打開的次要窗體
      if (focusedWindow.id === 1) {
        BrowserWindow.getAllWindows().forEach((win) => {
          if (win.id > 1) win.close();
        });
      }
      focusedWindow.webContents.session.clearStorageData(clearObj,() => {
        focusedWindow.reload();
      })
    }
  },
},
{
  label: '清除緩存數據',
  accelerator: 'CmdOrCtrl+Shift+Delete',
  click: (item,focusedWindow) => {
    if (focusedWindow) {
    	focusedWindow.webContents.session.clearStorageData(clearObj);
    }
  }
},

也可以使用開發者工具進行清除 chrome開發者工具

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章