-
+
- Тип: ext-error +
- + + + + +
diff --git a/extensions/chromium/minimalistic-pac-setter/extension/11-api-error-handlers.js b/extensions/chromium/minimalistic-pac-setter/extension/11-api-error-handlers.js
index aa1e5ff..fdd9fcf 100644
--- a/extensions/chromium/minimalistic-pac-setter/extension/11-api-error-handlers.js
+++ b/extensions/chromium/minimalistic-pac-setter/extension/11-api-error-handlers.js
@@ -4,7 +4,6 @@
const handlersState = function(key, value) {
- console.log(key, value, '!');
key = 'handlers-' + key;
if (value === null) {
return localStorage.removeItem(key);
@@ -21,6 +20,7 @@
};
const ifPrefix = 'if-on-';
+ const extName = chrome.runtime.getManifest().name;
window.apis.errorHandlers = {
@@ -67,29 +67,19 @@
},
- };
+ idToErr: {},
-}
-
-// INIT
-chrome.proxy.settings.get(
- {},
- (details) => window.apis.errorHandlers.isNotControlled(details)
-);
-
-{
-
- const extName = chrome.runtime.getManifest().name;
-
- const mayNotify = function(
- id, title, message,
+ mayNotify(
+ id, title, errOrMessage,
icon = 'default-128.png',
context = extName
) {
- if ( !window.apis.errorHandlers.isOn(id) ) {
+ if ( !this.isOn(id) ) {
return;
}
+ this.idToErr[id] = errOrMessage;
+ const message = errOrMessage.message || errOrMessage.toString();
chrome.notifications.create(
id,
{
@@ -103,31 +93,66 @@ chrome.proxy.settings.get(
}
);
- };
+ },
- window.addEventListener('error', (err) => {
+ installListenersOn(win, name, cb) {
- console.warn('GLOBAL ERROR', err);
- mayNotify('ext-error', 'Unhandled error', JSON.stringify(err),
- 'ext-error-128.png');
+ win.addEventListener('error', (errEvent) => {
+
+ console.warn(name + ':GLOBAL ERROR', errEvent);
+ this.mayNotify('ext-error', 'Ошибка расширения', errEvent,
+ 'ext-error-128.png');
+
+ });
+
+ win.addEventListener('unhandledrejection', (event) => {
+
+ console.warn(name + ':Unhandled rejection. Throwing error.');
+ event.preventDefault();
+ throw event.reason;
+
+ });
+
+ if (cb) {
+ // setTimeout changes error context.
+ setTimeout(cb, 0);
+ }
+
+ },
+
+ };
+
+}
+
+{
+
+ const handlers = window.apis.errorHandlers;
+
+ // INIT
+ chrome.proxy.settings.get(
+ {},
+ (details) => handlers.isNotControlled(details)
+ );
+
+ chrome.notifications.onClicked.addListener( function(notId) {
+
+ chrome.notifications.clear(notId);
+ if(notId === 'no-control') {
+ return chrome.tabs.create({active: true, url: 'chrome://settings/#proxy'});
+ }
+ chrome.tabs.create({active: true, url: './pages/view-error/index.html#' + notId});
});
- window.addEventListener('unhandledrejection', (event) => {
-
- console.warn('Unhandled rejection. Throwing error.');
- event.preventDefault();
- throw event.reason;
-
- });
+ handlers.installListenersOn(window, 'BG');
chrome.proxy.onProxyError.addListener((details) => {
- if (window.apis.errorHandlers.ifNoControl) {
+ if (handlers.ifNoControl) {
return;
}
console.warn('PAC ERROR', details);
- mayNotify('pac-error', ' PAC !', JSON.stringify(details),
+ handlers.mayNotify('pac-error', 'Ошибка PAC!', details,
'pac-error-128.png' );
});
@@ -136,8 +161,9 @@ chrome.proxy.settings.get(
console.log('Proxy settings changed.', details);
const noCon = 'no-control';
- if ( window.apis.errorHandlers.isNotControlled(details) ) {
- mayNotify(noCon, 'Proxy changed', JSON.stringify(details),
+ if ( handlers.isNotControlled(details) ) {
+ console.log(details);
+ handlers.mayNotify(noCon, 'Прокси контролирует другое расширение', details,
'no-control-128.png');
} else {
chrome.notifications.clear( noCon );
diff --git a/extensions/chromium/minimalistic-pac-setter/extension/12-api-sync-pac-script-with-pac-provider.js b/extensions/chromium/minimalistic-pac-setter/extension/12-api-sync-pac-script-with-pac-provider.js
index fc7743a..f914863 100644
--- a/extensions/chromium/minimalistic-pac-setter/extension/12-api-sync-pac-script-with-pac-provider.js
+++ b/extensions/chromium/minimalistic-pac-setter/extension/12-api-sync-pac-script-with-pac-provider.js
@@ -99,7 +99,7 @@
_periodicUpdateAlarmReason: 'Периодичное обновление PAC-скрипта Антизапрет',
- pushToStorage(cb) {
+ pushToStorageAsync(cb) {
console.log('Pushing to storage...');
@@ -143,7 +143,7 @@
},
*/
- syncWithPacProvider(key, cb) {
+ syncWithPacProviderAsync(key, cb) {
if( !key || typeof(key) === 'function' ) {
cb = key;
@@ -200,7 +200,7 @@
if (pacErr && ipsErr) {
return cb(pacErr, pacRes);
}
- this.pushToStorage(
+ this.pushToStorageAsync(
(pushErr) => cb(pacErr || ipsErr || pushErr, pacRes)
);
@@ -239,21 +239,21 @@
},
- installPac(key, cb) {
+ installPacAsync(key, cb) {
console.log('Installing PAC...');
if (!key) {
throw new Error('Key must be defined.');
}
if (this.currentProviderKey !== key) {
- return this.syncWithPacProvider(key, cb);
+ return this.syncWithPacProviderAsync(key, cb);
}
console.log(key + ' already installed.');
cb();
},
- clearPac(cb) {
+ clearPacAsync(cb) {
cb = asyncLogGroup('Cearing alarms and PAC...', cb);
chrome.alarms.clearAll(
@@ -266,7 +266,7 @@
return cb(err);
}
this.currentPacProviderKey = null;
- this.pushToStorage(cb);
+ this.pushToStorageAsync(cb);
}
)
@@ -296,7 +296,7 @@
'Periodic PAC update triggered:',
new Date().toLocaleString('ru-RU')
);
- antiCensorRu.syncWithPacProvider(/* Swallows errors. */);
+ antiCensorRu.syncWithPacProviderAsync(/* Swallows errors. */);
}
}
@@ -358,7 +358,7 @@
// UPDATE & MIGRATION
console.log('Extension updated.');
if (!ifAlarmTriggered) {
- antiCensorRu.pushToStorage(/* Swallows errors. */);
+ antiCensorRu.pushToStorageAsync(/* Swallows errors. */);
}
/*
@@ -414,7 +414,9 @@
args = replaceArgs;
}
const err = checkChromeError(stack);
- cb && cb.call(null, err, ...args);
+ if (cb) {
+ setTimeout( cb.bind(null, err, ...args), 0 );
+ }
};
diff --git a/extensions/chromium/minimalistic-pac-setter/extension/20-api-fixes.js b/extensions/chromium/minimalistic-pac-setter/extension/20-api-fixes.js
index 998915c..f05c5c2 100644
--- a/extensions/chromium/minimalistic-pac-setter/extension/20-api-fixes.js
+++ b/extensions/chromium/minimalistic-pac-setter/extension/20-api-fixes.js
@@ -4,20 +4,23 @@
(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
+
+ setTimeout is applied to Async methods only (name ends with Async)
*/
// Fix error context of methods of all APIs.
-for(const api of Object.keys(window.apis)) {
+/*
+for(const apiName of Object.keys(window.apis)) {
+ const api = window.apis[apiName];
for(const prop of Object.keys(api)) {
- if ( typeof(api[prop]) !== 'function' ) {
+ const method = api[prop];
+ if ( !(typeof(api[prop]) === 'function'
+ && method.name.endsWith('Async')) ) {
continue;
}
- const method = api[prop];
api[prop] = function(...args) {
setTimeout(method.bind(this, ...args), 0);
};
}
-}
-
-
+}*/
diff --git a/extensions/chromium/minimalistic-pac-setter/extension/manifest.json b/extensions/chromium/minimalistic-pac-setter/extension/manifest.json
index 295fdb6..9282edd 100755
--- a/extensions/chromium/minimalistic-pac-setter/extension/manifest.json
+++ b/extensions/chromium/minimalistic-pac-setter/extension/manifest.json
@@ -20,6 +20,7 @@
"contextMenus",
"notifications"
],
+
"background": {
"scripts": ["00-init-apis.js", "11-api-error-handlers.js", "12-api-sync-pac-script-with-pac-provider.js", "20-api-fixes.js", "30-block-informer.js", "40-context-menus.js"]
},
diff --git a/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.js b/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.js
index 9405386..6a94245 100755
--- a/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.js
+++ b/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.js
@@ -1,210 +1,211 @@
'use strict';
-chrome.runtime.getBackgroundPage( (backgroundPage) => {
+chrome.runtime.getBackgroundPage( (backgroundPage) =>
+ backgroundPage.apis.errorHandlers.installListenersOn(window, 'POPUP', () => {
- const getStatus = () => document.querySelector('#status');
+ const getStatus = () => document.querySelector('#status');
- const setStatusTo = (msg) => {
+ const setStatusTo = (msg) => {
- const status = getStatus();
- if (msg) {
- status.classList.remove('off');
- status.innerHTML = msg;
- } else {
- status.classList.add('off');
- }
-
- };
-
- const antiCensorRu = backgroundPage.apis.antiCensorRu;
-
- // SET DATE
-
- const setDate = () => {
-
- let dateForUser = 'никогда';
- if( antiCensorRu.lastPacUpdateStamp ) {
- let diff = Date.now() - antiCensorRu.lastPacUpdateStamp;
- let units = ' мс';
- const gauges = [
- [1000, ' с'],
- [60, ' мин'],
- [60, ' ч'],
- [24, ' дн'],
- [7, ' недель'],
- [4, ' месяцев'],
- [12, ' г'],
- ];
- for(const g of gauges) {
- const diffy = Math.floor(diff / g[0]);
- if (!diffy)
- break;
- diff = diffy;
- units = g[1];
+ const status = getStatus();
+ if (msg) {
+ status.classList.remove('off');
+ status.innerHTML = msg;
+ } else {
+ status.classList.add('off');
}
- dateForUser = diff + units + ' назад';
- }
-
- const dateElement = document.querySelector('.update-date');
- dateElement.innerText = dateForUser;
- dateElement.title = new Date(antiCensorRu.lastPacUpdateStamp)
- .toLocaleString('ru-RU');
-
- };
-
- setDate();
- chrome.storage.onChanged.addListener(
- (changes) => changes.lastPacUpdateStamp.newValue && setDate()
- );
-
- // CLOSE BUTTON
-
- document.querySelector('.close-button').onclick = () => window.close();
-
- // RADIOS
-
- const currentProviderRadio = () => {
-
- const id = antiCensorRu.currentPacProviderKey || 'none';
- return document.querySelector('#'+id);
-
- };
- const checkChosenProvider = () => currentProviderRadio().checked = true;
-
- const showError = (err) => {
-
- let clarification = err.clarification;
- const ifNotCritical = clarification && clarification.ifNotCritical;
- let message = err.message || '';
-
- while( clarification ) {
- message = (clarification && (clarification.message + ' ')) + message;
- clarification = clarification.prev;
- }
- message = message.trim();
- setStatusTo(
-`
-${ifNotCritical ? 'Некритичная ошибка.' : 'Ошибка!'}
-
-
-${message}
-[Ещё подробнее]`
- );
- getStatus().querySelector('.link-button').onclick = function() {
-
- const div = document.createElement('div');
- div.innerHTML = `
-Более подробную информацию можно узнать из логов фоновой страницы:
-
-chrome://extensions ›
-Это расширение › Отладка страниц: фоновая страница › Console (DevTools)
-
-Ещё: ${JSON.stringify({err: err, stack: err.stack})}
-`;
- getStatus().replaceChild(div, this);
- return false;
};
- };
+ const antiCensorRu = backgroundPage.apis.antiCensorRu;
- const enableDisableInputs = function() {
+ // SET DATE
- const inputs = document.querySelectorAll('input');
- for ( let i = 0; i < inputs.length; i++ ) {
- inputs[i].disabled = !inputs[i].disabled;
- }
+ const setDate = () => {
- };
-
- const conduct = (beforeStatus, operation, afterStatus, onSuccess) => {
-
- setStatusTo(beforeStatus);
- enableDisableInputs();
- operation((err) => {
- if (err) {
- showError(err);
- } else {
- setStatusTo(afterStatus);
- onSuccess && onSuccess();
+ let dateForUser = 'никогда';
+ if( antiCensorRu.lastPacUpdateStamp ) {
+ let diff = Date.now() - antiCensorRu.lastPacUpdateStamp;
+ let units = ' мс';
+ const gauges = [
+ [1000, ' с'],
+ [60, ' мин'],
+ [60, ' ч'],
+ [24, ' дн'],
+ [7, ' недель'],
+ [4, ' месяцев'],
+ [12, ' г'],
+ ];
+ for(const g of gauges) {
+ const diffy = Math.floor(diff / g[0]);
+ if (!diffy)
+ break;
+ diff = diffy;
+ units = g[1];
+ }
+ dateForUser = diff + units + ' назад';
}
+
+ const dateElement = document.querySelector('.update-date');
+ dateElement.innerText = dateForUser;
+ dateElement.title = new Date(antiCensorRu.lastPacUpdateStamp)
+ .toLocaleString('ru-RU');
+
+ };
+
+ setDate();
+ chrome.storage.onChanged.addListener(
+ (changes) => changes.lastPacUpdateStamp.newValue && setDate()
+ );
+
+ // CLOSE BUTTON
+
+ document.querySelector('.close-button').onclick = () => window.close();
+
+ // RADIOS
+
+ const currentProviderRadio = () => {
+
+ const id = antiCensorRu.currentPacProviderKey || 'none';
+ return document.querySelector('#'+id);
+
+ };
+ const checkChosenProvider = () => currentProviderRadio().checked = true;
+
+ const showError = (err) => {
+
+ let clarification = err.clarification;
+ const ifNotCritical = clarification && clarification.ifNotCritical;
+ let message = err.message || '';
+
+ while( clarification ) {
+ message = (clarification && (clarification.message + ' ')) + message;
+ clarification = clarification.prev;
+ }
+ message = message.trim();
+ setStatusTo(
+ `
+ ${ifNotCritical ? 'Некритичная ошибка.' : 'Ошибка!'}
+
+
+ ${message}
+ [Ещё подробнее]`
+ );
+ getStatus().querySelector('.link-button').onclick = function() {
+
+ const div = document.createElement('div');
+ div.innerHTML = `
+ Более подробную информацию можно узнать из логов фоновой страницы:
+
+ chrome://extensions ›
+ Это расширение › Отладка страниц: фоновая страница › Console (DevTools)
+
+ Ещё: ` + JSON.stringify({err: err, stack: err.stack});
+ getStatus().replaceChild(div, this);
+ return false;
+
+ };
+
+ };
+
+ const enableDisableInputs = function() {
+
+ const inputs = document.querySelectorAll('input');
+ for ( let i = 0; i < inputs.length; i++ ) {
+ inputs[i].disabled = !inputs[i].disabled;
+ }
+
+ };
+
+ const conduct = (beforeStatus, operation, afterStatus, onSuccess) => {
+
+ setStatusTo(beforeStatus);
enableDisableInputs();
- });
+ operation((err) => {
+ if (err) {
+ showError(err);
+ } else {
+ setStatusTo(afterStatus);
+ onSuccess && onSuccess();
+ }
+ enableDisableInputs();
+ });
- };
+ };
- const ul = document.querySelector('#list-of-providers');
- const _firstChild = ul.firstChild;
- for( const providerKey of Object.keys(antiCensorRu.pacProviders).sort() ) {
- const li = document.createElement('li');
- li.innerHTML = `
-
- [обновить]`;
- li.querySelector('.link-button').onclick =
- () => {
- conduct(
- 'Обновляем...', (cb) => antiCensorRu.syncWithPacProvider(cb),
- 'Обновлено.'
- );
+ const ul = document.querySelector('#list-of-providers');
+ const _firstChild = ul.firstChild;
+ for( const providerKey of Object.keys(antiCensorRu.pacProviders).sort() ) {
+ const li = document.createElement('li');
+ li.innerHTML = `
+
+ [обновить]`;
+ li.querySelector('.link-button').onclick =
+ () => {
+ conduct(
+ 'Обновляем...', (cb) => antiCensorRu.syncWithPacProviderAsync(cb),
+ 'Обновлено.'
+ );
+ return false;
+ };
+ ul.insertBefore( li, _firstChild );
+ }
+ checkChosenProvider();
+
+ const radios = [].slice.apply(
+ document.querySelectorAll('[name=pacProvider]')
+ );
+ for(const radio of radios) {
+ radio.onclick = function(event) {
+
+ if (event.target.id === (antiCensorRu.currentPacProviderKey || 'none')) {
+ return false;
+ }
+ const pacKey = event.target.id;
+ if (pacKey === 'none') {
+ conduct(
+ 'Отключение...',
+ (cb) => antiCensorRu.clearPacAsync(cb),
+ 'Отключено.',
+ checkChosenProvider
+ );
+ } else {
+ conduct(
+ 'Установка...',
+ (cb) => antiCensorRu.installPacAsync(pacKey, cb),
+ 'PAC-скрипт установлен.',
+ checkChosenProvider
+ );
+ }
return false;
};
- ul.insertBefore( li, _firstChild );
- }
- checkChosenProvider();
+ }
- const radios = [].slice.apply(
- document.querySelectorAll('[name=pacProvider]')
- );
- for(const radio of radios) {
- radio.onclick = function(event) {
+ const conpanel = document.getElementById('list-of-handlers');
+ backgroundPage.apis.errorHandlers.getEventsMap().forEach( (value, name) => {
- if (event.target.id === (antiCensorRu.currentPacProviderKey || 'none')) {
- return false;
- }
- const pacKey = event.target.id;
- if (pacKey === 'none') {
- conduct(
- 'Отключение...',
- (cb) => antiCensorRu.clearPac(cb),
- 'Отключено.',
- checkChosenProvider
- );
- } else {
- conduct(
- 'Установка...',
- (cb) => antiCensorRu.installPac(pacKey, cb),
- 'PAC-скрипт установлен.',
- checkChosenProvider
- );
- }
- return false;
- };
- }
+ const li = document.createElement('li');
+ li.innerHTML = `
+
+ `;
+ const box = li.querySelector('input');
+ box.checked = backgroundPage.apis.errorHandlers.isOn(name);
+ box.onclick = function() {
- const conpanel = document.getElementById('list-of-handlers');
- backgroundPage.apis.errorHandlers.getEventsMap().forEach( (value, name) => {
+ const id = this.id.replace('if-on-', '');
+ backgroundPage.apis.errorHandlers.switch(this.checked ? 'on' : 'off', id);
- const li = document.createElement('li');
- li.innerHTML = `
-
- `;
- const box = li.querySelector('input');
- box.checked = backgroundPage.apis.errorHandlers.isOn(name);
- box.onclick = function() {
+ };
+ conpanel.appendChild(li);
- const id = this.id.replace('if-on-', '');
- backgroundPage.apis.errorHandlers.switch(this.checked ? 'on' : 'off', id);
+ });
- };
- conpanel.appendChild(li);
+ setStatusTo('');
+ if (antiCensorRu.ifFirstInstall) {
+ const id = antiCensorRu.currentPacProviderKey || 'none';
+ document.querySelector('#update-' + id).click();
+ }
- });
-
- setStatusTo('');
- if (antiCensorRu.ifFirstInstall) {
- const id = antiCensorRu.currentPacProviderKey || 'none';
- document.querySelector('#update-' + id).click();
- }
-
-});
+ })
+);
diff --git a/extensions/chromium/minimalistic-pac-setter/extension/pages/view-error/err.jpg b/extensions/chromium/minimalistic-pac-setter/extension/pages/view-error/err.jpg
new file mode 100644
index 0000000..61fae22
Binary files /dev/null and b/extensions/chromium/minimalistic-pac-setter/extension/pages/view-error/err.jpg differ
diff --git a/extensions/chromium/minimalistic-pac-setter/extension/pages/view-error/index.html b/extensions/chromium/minimalistic-pac-setter/extension/pages/view-error/index.html
new file mode 100644
index 0000000..8344142
--- /dev/null
+++ b/extensions/chromium/minimalistic-pac-setter/extension/pages/view-error/index.html
@@ -0,0 +1,75 @@
+
+
+