mirror of
https://github.com/tubearchivist/browser-extension.git
synced 2024-12-24 10:50:13 +00:00
fix backgound.js listener callback, take 3
This commit is contained in:
parent
1dd2d503cc
commit
aff7c50f94
@ -116,21 +116,25 @@ async function downloadLink(toDownload) {
|
||||
}
|
||||
|
||||
|
||||
// event listener for messages from script.js and popup.js
|
||||
browserType.runtime.onMessage.addListener(
|
||||
(data, sender) => {
|
||||
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);
|
||||
}
|
||||
// process and return message if needed
|
||||
function handleMessage(request, sender, sendResponse) {
|
||||
console.log("message background.js listener: " + JSON.stringify(request));
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user