DEPRECATION WARNING

The Qvault password manager is a deprecated project, this article remains live for historical informational purposes only. Our new product can be found at Qvault Classroom.

We recently added “Offline Mode” to Qvault as a new feature. This was in preparation to also add Bitcoin and cryptocurrency key generation. There is now a toggle switch at the top of the app that, when switched off, ensures that the app will make no network requests.

You have always been able to use Qvault offline, that is, assuming the user chose not to sign up for Qvault’s cloud backup option. Now, even if a user is storing their encrypted vault files on Qvault servers, the user can choose to go offline and work locally temporarily.

How Does it Work?

Electron has an API that allows developers to intercept and modify web requests. By intercepting all webRequests before they are made using the onBeforeRequest hook, we can check them see if we want to allow each request or not. For example:

// callback({cancel: true}) stops the request before it is sent. // callback({cancel: false}) sends the webRequest mainWindow.webContents.session.webRequest.onBeforeRequest({ // Intercept all webRequests urls: [ '<all_urls>' ] }, (details, callback) => { // allow all filesystem calls if (details.url.substring(0, details.url.indexOf(':')) == 'file'){ callback({cancel: false}); return; } // don't allow any network calls if in offlineMode if (!onlineMode){ callback({cancel: true}); return; } // allow al other network calls callback({cancel: false}); });

Hopefully, this helps anyone else looking to control webRequests in Electron, and helps our users understand ‘offline mode’ in Qvault! Thanks for reading.

Thanks For Reading! Follow us on Twitter @q_vault if you have any questions or comments Take some coding courses on our new platform Subscribe to our Newsletter for more programming articles