diff --git a/packages/nocap/src/classes/Base.js b/packages/nocap/src/classes/Base.js index 8c9faea3..328d4d53 100644 --- a/packages/nocap/src/classes/Base.js +++ b/packages/nocap/src/classes/Base.js @@ -116,6 +116,7 @@ export default class { * @returns {Promise<*>} - The result of the check */ async _check(key){ + if(!this.can_check(key)) return this.logger.debug(`${key}: check()`) this.defaultAdapters() const precheck = await this.start(key).catch( err => this.logger.debug(err) ) @@ -126,6 +127,14 @@ export default class { return result } + can_check(key){ + if(this.is_browser() && key === 'ssl') { + this.logger.err('Cannot check SSL from browser') + return + } + return true + } + /** * maybeTimeoutReject * Creates a reject function for a timeout scenario @@ -986,8 +995,20 @@ export default class { * @param {Error} error - The error to throw * @returns {Promise<*>} - A promise that rejects with the provided error */ - throw(error){ - return Promise.reject(error); - } + throw(error){ + return Promise.reject(error); + } + + /** + * is_browser + * Returns true if in a browser environment + * + * @private + * @returns {boolean} + */ + is_browser(){ + (typeof window !== 'undefined' && typeof document !== 'undefined') + } + } diff --git a/packages/utils/index.js b/packages/utils/index.js index 4bf3a796..9f2986c2 100644 --- a/packages/utils/index.js +++ b/packages/utils/index.js @@ -11,6 +11,8 @@ let { DAEMON_PUBKEY } = process.env; DAEMON_PUBKEY = DAEMON_PUBKEY? DAEMON_PUBKEY : 'WARNING_DAEMON_PUBKEY_UNSET'; export { DAEMON_PUBKEY } +export const isBrowser = () => (typeof window !== 'undefined' && typeof document !== 'undefined') + export const parseRelayNetwork = network.parseRelayNetwork export const relaysSerializedByNetwork = network.relaysSerializedByNetwork