(function(window) { 'use strict'; new ExceptionHandler(); window.app = window.app || {}; app.ErrorPageFactory = Polymer({ is: 'error-page', behaviors: [ Chrome.LocalizeBehavior, ], properties: { lastError: { type: Object, value: function() { return new Chrome.Storage.LastError(); }, notify: true, }, }, ready: function() { Chrome.Storage.getLastError().then((lastError) => { this.set('lastError', lastError); return Promise.resolve(); }).catch((err) => { Chrome.GA.error(err.message, 'ErrorPage.ready'); }); chrome.storage.onChanged.addListener((changes) => { // listen for changes to lastError for (const key in changes) { if (changes.hasOwnProperty(key)) { if (key === 'lastError') { const change = changes[key]; this.set('lastError', change.newValue); break; } } } }); }, /** * Event: Email support * @private */ _onEmailTapped: function() { let body = app.Utils.getEmailBody(); body = body + `${this.lastError.title}\n\n${this.lastError.message}\n\n` + `${this.lastError.stack}`; body = body + '\n\nPlease provide any additional info. ' + 'on what led to the error.\n\n'; const url = app.Utils.getEmailUrl('Last Error', body); Chrome.GA.event(Chrome.GA.EVENT.ICON, 'LastError email'); chrome.tabs.create({url: url}); }, /** * Event: Remove the error * @private */ _onRemoveTapped: function() { Chrome.Storage.clearLastError(); Chrome.GA.event(Chrome.GA.EVENT.ICON, 'LastError delete'); }, /** * Computed Binding * @param {Chrome.Storage.LastError} lastError - the error * @returns {string} stack trace * @private */ _computeStack: function(lastError) { let ret = ''; if (lastError.message) { ret += lastError.stack; } return ret; }, /** * Computed Binding * @param {Chrome.Storage.LastError} lastError - the error * @returns {string} page title * @private */ _computeTitle: function(lastError) { let ret = Chrome.Locale.localize('last_error_viewer_title'); if (lastError.message) { ret += ` - ${lastError.title}`; } return ret; }, }); })(window);