Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #243 from QwantResearch/masq-browsers
Browse files Browse the repository at this point in the history
Disable Masq on unsupported browsers
  • Loading branch information
jbgriesner authored Jun 12, 2019
2 parents e5f9fc1 + dc0223b commit ed7e72a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"babel-jest": "^24.1.0",
"babel-loader": "^8.0.4",
"babel-preset-env": "1.7.0",
"detect-browser": "^4.5.1",
"dot": "https://github.com/olado/doT.git#299b4da",
"dot-loader": "^0.1.2",
"esdoc": "^1.1.0",
Expand Down
9 changes: 7 additions & 2 deletions src/adapters/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import ExtendedString from '../libs/string';
import LocalStore from '../libs/local_store';
import MasqStore from '../libs/masq';

export default class Store {
const masqConfig = nconf.get().masq;
if (!MasqStore.isMasqSupported() && !MasqStore.isMasqForced()) {
masqConfig.enabled = false;
}

export default class Store {
constructor() {
// get store from window if already initialized
if (window.__store) {
Expand All @@ -21,9 +25,10 @@ export default class Store {
// init stores
this.localStore = new LocalStore();
this.abstractStore = this.localStore;
this.masqConfig = nconf.get().masq;
this.masqConfig = masqConfig;
this.masqInitialized = true;
if (this.masqConfig.enabled) {

this.masqEventTarget = document.createElement('masqStore');

this.masqStore = new MasqStore(this.masqConfig);
Expand Down
21 changes: 21 additions & 0 deletions src/libs/masq.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Error from '../adapters/error';
import MasqActivatingModal from '../modals/masq_activating_modal';
import importMasq from './import_masq';
import Poi from '../adapters/poi/poi';
import { detect } from 'detect-browser';

const handleError = (fct, msg, e) => {
Error.sendOnce('masq_store', fct, msg, e);
Expand Down Expand Up @@ -175,4 +176,24 @@ export default class MasqStore {
throw e;
}
}

static isMasqForced() {
let urlParams = new URLSearchParams(window.location.search);
return urlParams.get('masq') === '1';
}

static isMasqSupported() {
const SUPPORTED_BROWSERS = ['chrome', 'firefox', 'safari'];
const browser = detect();
if (!browser) {
return false;
}
const isSupportedPlatform = browser.os && (
browser.os.startsWith('Windows')
|| browser.os === 'Linux'
|| browser.os === 'Mac OS'
);
const isSupportedBrowser = SUPPORTED_BROWSERS.indexOf(browser.name) !== -1;
return isSupportedPlatform && isSupportedBrowser;
}
}
3 changes: 2 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import '@babel/polyfill';
import 'url-search-params-polyfill';
import I18n from './libs/i18n';
import './libs/listen';
import './libs/actions';
import App from './panel/app_panel';
import './proxies/panel_manager';
import UrlState from './proxies/url_state';
import Store from './adapters/store';
import UrlState from './proxies/url_state';

/* global PanelManager */
(async function main() {
Expand Down
3 changes: 1 addition & 2 deletions src/proxies/url_shards.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {paramTypes} from './url_shard';
import 'url-search-params-polyfill';

function UrlShards() {}

Expand Down Expand Up @@ -90,4 +89,4 @@ UrlShards.parseUrl = function() {
return shards;
};

export default UrlShards;
export default UrlShards;

0 comments on commit ed7e72a

Please sign in to comment.