fix backgound.js listener callback, take 3

This commit is contained in:
simon 2022-04-04 11:58:50 +07:00
parent 1dd2d503cc
commit aff7c50f94
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -116,21 +116,25 @@ async function downloadLink(toDownload) {
} }
// event listener for messages from script.js and popup.js // process and return message if needed
browserType.runtime.onMessage.addListener( function handleMessage(request, sender, sendResponse) {
(data, sender) => { console.log("message background.js listener: " + JSON.stringify(request));
console.log("message background.js listener: " + JSON.stringify(data))
if (data.verify === true) {
let response = verifyConnection()
return Promise.resolve(response);
} else if (data.youtube) {
setYoutubeLink(data)
} else if (data.download) {
let response = downloadLink(data.download.url)
return Promise.resolve(response);
}
return false; if (request.verify === true) {
let response = verifyConnection();
response.then(message => {
sendResponse(message);
})
} else if (request.youtube) {
setYoutubeLink(request)
} else if (request.download) {
let response = downloadLink(request.download.url);
response.then(message => {
sendResponse(message)
})
} }
);
return true;
}
browserType.runtime.onMessage.addListener(handleMessage);