odoo.define('web.ErrorDialogRegistry', function (require) { "use strict"; var Registry = require('web.Registry'); return new Registry(); }); odoo.define('web.CrashManager', function (require) { "use strict"; const AbstractService = require('web.AbstractService'); var ajax = require('web.ajax'); const BrowserDetection = require('web.BrowserDetection'); var core = require('web.core'); var Dialog = require('web.Dialog'); var ErrorDialogRegistry = require('web.ErrorDialogRegistry'); var Widget = require('web.Widget'); var _t = core._t; var _lt = core._lt; // Register this eventlistener before qunit does. // Some errors needs to be negated by the crash_manager. window.addEventListener('unhandledrejection', ev => core.bus.trigger('crash_manager_unhandledrejection', ev) ); let active = true; /** * An extension of Dialog Widget to render the warnings and errors on the website. * Extend it with your template of choice like ErrorDialog/WarningDialog */ var CrashManagerDialog = Dialog.extend({ xmlDependencies: (Dialog.prototype.xmlDependencies || []).concat( ['/web/static/src/xml/crash_manager.xml'] ), /** * @param {Object} error * @param {string} error.message the message in Warning/Error Dialog * @param {string} error.traceback the traceback in ErrorDialog * * @constructor */ init: function (parent, options, error) { this._super.apply(this, [parent, options]); this.message = error.message; this.traceback = error.traceback; core.bus.off('close_dialogs', this); }, }); var ErrorDialog = CrashManagerDialog.extend({ template: 'CrashManager.error', }); var WarningDialog = CrashManagerDialog.extend({ template: 'CrashManager.warning', /** * Sets size to medium by default. * * @override */ init: function (parent, options, error) { this._super(parent, _.extend({ size: 'medium', }, options), error); }, //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- /** * Focuses the ok button. * * @override */ open: function () { this._super({shouldFocusButtons: true}); }, }); var CrashManager = AbstractService.extend({ init: function () { var self = this; active = true; this.isConnected = true; this.odooExceptionTitleMap = { 'odoo.addons.base.models.ir_mail_server.MailDeliveryException': _lt("MailDeliveryException"), 'odoo.exceptions.AccessDenied': _lt("Access Denied"), 'odoo.exceptions.AccessError': _lt("Access Error"), 'odoo.exceptions.MissingError': _lt("Missing Record"), 'odoo.exceptions.UserError': _lt("User Error"), 'odoo.exceptions.ValidationError': _lt("Validation Error"), 'odoo.exceptions.Warning': _lt("Warning"), }; this.browserDetection = new BrowserDetection(); this._super.apply(this, arguments); // crash manager integration core.bus.on('rpc_error', this, this.rpc_error); window.onerror = function (message, file, line, col, error) { // Scripts injected in DOM (eg: google API's js files) won't return a clean error on window.onerror. // The browser will just give you a 'Script error.' as message and nothing else for security issue. // To enable onerror to work properly with CORS file, you should: // 1. add crossorigin="anonymous" to your