I'm developing an electron application that uses a combo of the electron API and devtools protocol for browser automation. I'm running into an issue where javascript files are being retrieved from memory cache on page reload even after clearing the cache. This happens using both the electron API and using the devtools protocol for clearing the cache.
My question is if memory cache is supposed to be cleared when the Network.clearBrowserCache devtools
command (or session.clearCache()
electron API call) is executed? If so, why might it not be happening in my case? If not, how do I clear the memory cache in addition to the disk cache?
Here are some code snippets using both the electron API and devtools protocol to clear the cache:
Electron:
browserWindow.webContents.openDevTools();
await new Promise((resolve) => setTimeout(resolve, 5000));
await browserWindow.webContents.loadURL('https://mozenda-electron-test.s3-us-west-2.amazonaws.com/Mozenda-Electron-Test/RequestManager/RequestBlocking.html');
await new Promise((resolve) => setTimeout(resolve, 3000));
await browserWindow.webContents.session.clearCache();
await browserWindow.webContents.session.clearStorageData();
await browserWindow.webContents.reload();
await new Promise((resolve) => setTimeout(resolve, 3000));
DevTools Protocol:
browserWindow.webContents.openDevTools();
await new Promise((resolve) => setTimeout(resolve, 5000));
await browserWindow.webContents.loadURL('https://mozenda-electron-test.s3-us-west-2.amazonaws.com/Mozenda-Electron-Test/RequestManager/RequestBlocking.html');
await new Promise((resolve) => setTimeout(resolve, 3000));
const devtools = new DevTools();
await devtools.CommandExecute('Network.clearBrowserCache');
await browserWindow.webContents.reload();
await new Promise((resolve) => setTimeout(resolve, 3000));
...
export class DevTools
{
private _browser: BrowserWindow;
public constructor(browser: BrowserWindow)
{
this._browser = browser;
try
{
this._browser.webContents.debugger.attach('1.3');
}
catch (err)
{
LogHelper.WriteError('DevToolsCommandExecute', 'Debugger attach failed : ', err);
}
}
public async CommandExecute(method: string, params: unknown = {}, timeoutMS = 100): Promise<unknown>
{
return Promise.race([this._browser.webContents.debugger.sendCommand(method, params), new Promise((_resolve, reject) =>
{
setTimeout(() => reject('Timed out in '+ timeoutMS + 'ms.'), timeoutMS);
})]).catch((error) =>
{
LogHelper.WriteError('CommandExecuteError:', method, error);
throw error;
});
}
}
And here's the result I see in the DevTools network window with either of these: DevTools network info