Расширение Google Chrome - главное окно закрывается после получения кода с URL-адреса перенаправления
Я пытаюсь разработать систему входа OAuth в расширение Google Chrome, несмотря на то, что главное окно исчезло, когда я пытаюсь получить ответ от обратного вызова.
// фон.js
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.message === 'login') {
console.log("Login success - ");
user_signed_in = true;
sendResponse('success');
chrome.identity.launchWebAuthFlow({
// url: `https://discord.com/api/oauth2/authorize?client_id=937186052412678185&permissions=8&redirect_uri=https%3A%2F%2Focdecabdmpigonkcbncodnpgepjjnehm.chromiumapp.org%2F&response_type=code&scope=identify%20email%20guilds%20bot`,
url: DISCORD_URI,
interactive: true
}, function (redirect_uri) {
// console.log("Background - ", redirect_uri);
if (chrome.runtime.lastError || redirect_uri.includes('access_denied')) {
console.log("Could not authenticate.");
sendResponse('fail');
} else {
console.log("Login success - ");
user_signed_in = true;
sendResponse('success');
}
sendResponse('success');
});
/*
*/
return true;
}
});