mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
[mv3] Simplify sendMessage
onMessage() is now a listener installed synchrnously when uBOL
executes, so no longer need to deal with failure to send messages.
Related commit:
ab458b492a
This commit is contained in:
parent
22e848c9c2
commit
1d53441456
1 changed files with 2 additions and 15 deletions
|
|
@ -34,21 +34,8 @@ export const windows = browser.windows;
|
|||
// send a message, we try a few more times when the message fails to be sent.
|
||||
|
||||
export function sendMessage(msg) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let i = 5;
|
||||
const send = ( ) => {
|
||||
runtime.sendMessage(msg).then(response => {
|
||||
resolve(response);
|
||||
}).catch(reason => {
|
||||
i -= 1;
|
||||
if ( i <= 0 ) {
|
||||
reject(reason);
|
||||
} else {
|
||||
setTimeout(send, 200);
|
||||
}
|
||||
});
|
||||
};
|
||||
send();
|
||||
return runtime.sendMessage(msg).catch(reason => {
|
||||
console.log(reason);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue