diff --git a/packages/cozy-pouch-link/src/PouchManager.js b/packages/cozy-pouch-link/src/PouchManager.js index 6f10073657..4f7fb68324 100644 --- a/packages/cozy-pouch-link/src/PouchManager.js +++ b/packages/cozy-pouch-link/src/PouchManager.js @@ -41,6 +41,7 @@ class PouchManager { options.platform?.storage || platformWeb.storage ) this.PouchDB = options.platform?.pouchAdapter || platformWeb.pouchAdapter + this.isOnline = options.platform?.isOnline || platformWeb.isOnline } async init() { @@ -170,7 +171,7 @@ class PouchManager { /** Starts replication */ async replicateOnce() { - if (!window.navigator.onLine) { + if (!(await this.isOnline())) { logger.info( 'PouchManager: The device is offline so the replication has been skipped' ) diff --git a/packages/cozy-pouch-link/src/platformWeb.js b/packages/cozy-pouch-link/src/platformWeb.js index e09b9de5ca..168b8a3391 100644 --- a/packages/cozy-pouch-link/src/platformWeb.js +++ b/packages/cozy-pouch-link/src/platformWeb.js @@ -12,7 +12,12 @@ const storage = { } } +const isOnline = async () => { + return window.navigator.onLine +} + export const platformWeb = { storage, - pouchAdapter: PouchDB + pouchAdapter: PouchDB, + isOnline }