Add error handlers, fix error context, add icons

This commit is contained in:
Ilya Ig. Petrov 2016-12-01 01:58:52 -08:00
parent 00221bb96e
commit 257495168c
7 changed files with 85 additions and 25 deletions

View File

@ -0,0 +1,56 @@
'use strict';
{
const extName = chrome.runtime.getManifest().name;
const notify = (
id,
title,
message,
icon = 'default-128.png',
context = extName
) => chrome.notifications.create(
id,
{
title: title,
message: message,
contextMessage: context,
requireInteraction: true,
type: 'basic',
iconUrl: './icons/' + icon,
}
);
window.addEventListener('error', (err) => {
console.warn('Global error');
notify('Unhandled error', 'Unhandled error', JSON.stringify(err),
'ext-error-128.png');
});
window.addEventListener('unhandledrejection', (event) => {
console.warn('Unhandled rejection. Throwing error.');
event.preventDefault();
throw event.reason;
});
chrome.proxy.onProxyError.addListener((details) => {
console.warn('PAC ERROR:', details);
notify('pac-error', ' PAC !', JSON.stringify(details),
'pac-error-128.png' );
});
chrome.proxy.settings.onChange.addListener((details) => {
console.log('Proxy settings changed.', details);
// const ifOther = details.levelOfControl.startsWith('controlled_by_other');
notify('Proxy change', 'Proxy changed', JSON.stringify(details),
'no-control-128.png');
});
}

View File

@ -20,6 +20,28 @@
version: chrome.runtime.getManifest().version,
fixErrorsContext() {
/* `setTimeout` changes context of execution from other window
(e.g. popup) to background window, so we may catch errors
in bg error handlers.
More: https://bugs.chromium.org/p/chromium/issues/detail?id=357568
*/
for(const prop of Object.keys(this)) {
if ( typeof(this[prop]) === 'function' ) {
const method = this[prop];
this[prop] = function(...args) {
setTimeout(method.bind(this, ...args), 0);
};
}
}
},
throw() {
throw new Error('Artificial error');
},
pacProviders: {
Антизапрет: {
pacUrl: 'https://antizapret.prostovpn.org/proxy.pac',
@ -286,6 +308,8 @@
In such case extension _should_ try to work on default parameters.
*/
const antiCensorRu = window.antiCensorRu;
antiCensorRu.fixErrorsContext();
chrome.alarms.onAlarm.addListener(
(alarm) => {
@ -508,7 +532,7 @@
err = e || err || {clarification: {message: ''}};
err.clarification = err.clarification || {message: ''};
err.clarification.message = (
error.clarification.message
err.clarification.message
+ ' Сервер (текст): '+ res
).trim();
err.data = err.data || res;
@ -604,24 +628,3 @@
}
}
window.addEventListener('error', (err) => {
console.error('Global error');
});
window.addEventListener('unhandledrejection', (event) => {
console.warn('Unhandled rejection. Throwing error.');
event.preventDefault();
throw event.reason;
});
chrome.proxy.settings.onChange.addListener((details) => {
console.log('Proxy settings changed.', details);
// const ifOther = details.levelOfControl.startsWith('controlled_by_other');
});

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@ -5,7 +5,7 @@
"description": "Аргументы против цензуры: https://git.io/vEkI9",
"version": "0.0.0.15",
"icons": {
"128": "/icons/ribbon128.png"
"128": "/icons/default-128.png"
},
"author": "ilyaigpetrov@gmail.com",
"homepage_url": "https://github.com/anticensorship-russia/chromium-extension",
@ -17,10 +17,11 @@
"storage",
"<all_urls>",
"tabs",
"contextMenus"
"contextMenus",
"notifications"
],
"background": {
"scripts": ["1-sync-pac-script-with-pac-provider.js", "2-block-informer.js", "3-context-menus.js"]
"scripts": ["0-error-handlers.js", "1-sync-pac-script-with-pac-provider.js", "2-block-informer.js", "3-context-menus.js"]
},
"browser_action": {
"default_title": "Этот сайт благословлён",