Skip to content
This repository was archived by the owner on Feb 12, 2023. It is now read-only.

Commit d34cb15

Browse files
author
Ke, Mingze
committed
Don't throw chrome.runtime.lastError by default
1 parent 7f1297b commit d34cb15

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

‎chrome-app/eventPage.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@
134134
function removeListener(objName, portName, id) {
135135
if (listenerMap[objName]) {
136136
if (typeof id === 'undefined') {
137-
listenerMap[objName].receivers.forEach(function (receiver, idx) {
138-
if (receiver.portName === portName) {
139-
listenerMap[objName].receivers.splice(idx, 1);
140-
}
137+
listenerMap[objName].receivers = listenerMap[objName].receivers.filter(function (receiver) {
138+
return receiver.portName !== portName;
141139
});
142140
} else {
143141
listenerMap[objName].receivers.some(function (receiver, idx) {

‎chrome-app/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "API Proxy for Google Chrome™",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"manifest_version": 2,
55
"minimum_chrome_version": "23",
66
"app": {

‎lib/chrome._api.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ chrome._api = (function (window) {
4646
}
4747

4848
function invoke(id, method, params) {
49+
delete chrome.runtime.lastError;
4950
window.postMessage({
5051
jsonrpc: '2.0',
5152
id: id,
@@ -59,14 +60,16 @@ chrome._api = (function (window) {
5960

6061
if (msg.jsonrpc && !msg.method) {
6162
if (msg.error) {
62-
throw msg.error;
63-
} else if (msg.result) {
64-
if (callbackHash[msg.id]) {
65-
callbackHash[msg.id].apply(undef, msg.result);
66-
delete callbackHash[msg.id];
67-
} else if (listenerHash[msg.id]) {
68-
listenerHash[msg.id].apply(undef, msg.result);
69-
}
63+
chrome.runtime.lastError = {
64+
message: msg.error
65+
};
66+
}
67+
68+
if (callbackHash[msg.id]) {
69+
callbackHash[msg.id].apply(undef, msg.result);
70+
delete callbackHash[msg.id];
71+
} else if (listenerHash[msg.id]) {
72+
listenerHash[msg.id].apply(undef, msg.result);
7073
}
7174
}
7275
}, false);
@@ -78,3 +81,5 @@ chrome._api = (function (window) {
7881
};
7982

8083
}(window));
84+
85+
chrome.runtime = chrome.runtime || {};

0 commit comments

Comments
 (0)