I’m trying to make a browser extension (currently trying to make it for Google Chrome, will try for Firefox and other later) that send a notification when a specific streamer is streaming. I’ve already done the notification part but I have two problems on my hands
-
Is using Twitch API: I’ve searched a bit and what I’ve understood is that I need to make the user authorize the Twitch extension I was forced to create so I can have a Oauth Token from them and my client-id and secret from the twitch extension. Is that really the case or there is a workaround? Because some people may not want to link their twitch account to the extension for that and could be seen as a phishing attempt.
-
I’m using chrome.alarms for checking every x minutes if the user is streaming but I read on Google Chrome dev website that sometime closing the brower or other thing can reset/delete the alarm and I would like to know how to prevent that ?
Currently the small work around that I’ve found for the API problem is fetching the channel link of the user and searching for the isBroadcasting string to check if they are streaming, but I know that using this method is seen as a bad practice and would like to use the API, since then it would be easier to get the stream title, game name, game boxart etc
Here is my current code for getting if the user is streaming:
async function checkIfLive(username) {
try {
const response = await fetch(`https://twitch.tv/${username}`);
const sourceCode = await response.text();
if (sourceCode.includes("isLiveBroadcast")) {
showNotification({ message: "Is streaming", title: "Debug" });
}
else {
showNotification({ message: "Is not streaming", title: "Debug" });
}
}
catch (error) {
showNotification({ message: "Error", title: "Debug" });
}
}
let username = "<TWITCH_USERNAME>";
checkIfLive(username);