diff --git a/src/index.js b/src/index.js index 70dda5a90ca..c5bbb734c1d 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,4 @@ +import './lib/log-suppression'; import GUI from './containers/gui.jsx'; import AppStateHOC from './lib/app-state-hoc.jsx'; import GuiReducer, {guiInitialState, guiMiddleware, initEmbedded, initFullScreen, initPlayer} from './reducers/gui'; diff --git a/src/lib/log-suppression.js b/src/lib/log-suppression.js new file mode 100644 index 00000000000..f238fac9a48 --- /dev/null +++ b/src/lib/log-suppression.js @@ -0,0 +1,53 @@ +/** + * Suppress certain console warnings that are known upstream issues or intentional. + */ + +const ignoredWarnings = [ + 'Object freezing is not supported by Opal', + 'Canvas2D: Multiple readback operations using getImageData are faster ' + + 'with the willReadFrequently attribute set to true', + 'Support for defaultProps will be removed from function components', + 'React does not recognize the colorMode prop on a DOM element', + 'React does not recognize the showNewFeatureCallouts prop on a DOM element', + 'React does not recognize the localesOnly prop on a DOM element', + 'React does not recognize the setTheme prop on a DOM element', + 'React does not recognize the', + 'The prop `projectId` is marked as required in `StageHeaderComponent`, but its value is `null`', + 'Invalid prop `projectId` of type `string` supplied to `StageHeaderComponent`, expected `number`', + 'The prop projectId is marked as required in StageHeaderComponent, but its value is null', + 'Invalid prop projectId of type string supplied to StageHeaderComponent, expected number', + 'componentWillMount has been renamed', + 'componentWillReceiveProps has been renamed', + 'findDOMNode is deprecated', + 'The AudioContext was not allowed to start', + 'apple-mobile-web-app-capable', + 'GenerateSW has been called multiple times' +]; + +/** + * Check if a message should be ignored. + * @param {string} message The message to check. + * @param {Array} args Additional arguments. + * @returns {boolean} True if the message should be ignored. + */ +const shouldIgnore = (message, ...args) => { + const allStrings = [message, ...args].filter(arg => typeof arg === 'string'); + return allStrings.some(str => + ignoredWarnings.some(ignored => str.includes(ignored)) + ); +}; + +/* eslint-disable no-console */ +const originalWarn = console.warn; +const originalError = console.error; + +console.warn = function (message, ...args) { + if (shouldIgnore(message, ...args)) return; + originalWarn.apply(console, [message, ...args]); +}; + +console.error = function (message, ...args) { + if (shouldIgnore(message, ...args)) return; + originalError.apply(console, [message, ...args]); +}; +/* eslint-enable no-console */ diff --git a/src/playground/index.ejs b/src/playground/index.ejs index 6b2b3a09833..017e81e779e 100644 --- a/src/playground/index.ejs +++ b/src/playground/index.ejs @@ -13,6 +13,8 @@ <% } %> + + <% const originTrials = htmlWebpackPlugin.options.originTrials; diff --git a/src/playground/index.jsx b/src/playground/index.jsx index 6ff33f7e8b5..fb37fe758ba 100644 --- a/src/playground/index.jsx +++ b/src/playground/index.jsx @@ -4,6 +4,8 @@ import 'core-js/fn/array/includes'; import 'core-js/fn/promise/finally'; import 'intl'; // For Safari 9 +import '../lib/log-suppression'; + import React from 'react'; import ReactDOM from 'react-dom'; diff --git a/src/playground/player.jsx b/src/playground/player.jsx index ae4cba1c9e7..eee1345b238 100644 --- a/src/playground/player.jsx +++ b/src/playground/player.jsx @@ -1,3 +1,4 @@ +import '../lib/log-suppression'; import classNames from 'classnames'; import PropTypes from 'prop-types'; import React from 'react';