I am developing extension in manifest version 3. My extenison’s purpose is to notify user if they are using chrome for more than 2 hours. i have created notification via timer in background.js and when a user clicks on the button at notification it must open Break.html in new tab at browser. I have done this functionality. Now, I want to turn off my extension from button at POPUP.HTML via popup.js. So that, when a user clicks on this button it must stop seeing those notifications from my extension. I have used
chrome.management.setEnabled("Extension ID", false);
but this entirely stops my extension from chrome://extensions/ I want some other way to stop my extension.
here is my code:
BACKGROUND.JS
//===creating notification===
var notifyTimer = setInterval(func,20000);
function func(){
var opt = {
type: "image",
title: "E-Gym",
message: "You have been working for too long on Chrome. Would you like to take a break?",
iconUrl: "logo.png",
requireInteraction: true,
imageUrl: "background.png",
buttons: [{
title: "Let's Begin Workout" }]
};
chrome.notifications.create(opt, creationCallback);
function creationCallback(id){
myNotificationID = id;
}
}
//===Opening break page when notification button is clicked======
chrome.notifications.onButtonClicked.addListener(function(notifId) {
chrome.tabs.create({ url: "break.html" })
});
POPUP.HTML:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="storyboardstyle.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body style="width: 280px; height: 210px; background-color:#f9c8c4">
<div style="position: absolute; left:5px; top:5px; background-color: none; border: 2px solid rgb(203, 50, 91); color:antiquewhite; width:270px; height: 200px;"></div>
<div id="heading-gympass"><h1><b>E-GYM</b></h1>
<button id="stop_btn">Stop Extension</button><div>
<script src="popup.js"></script>
</body>
</html>
POPUP.JS
const startBtn = document.getElementById("stop_btn");
startBtn.addEventListener("click", myFunction);
function myFunction() {
// I WANT SOME CODE to stop extension
// I have used chrome.management but it disables my entire extension from chrome://extensions/
// chrome.management.setEnabled("Extension ID", false);
}
I want to write some code in popup.js to stop my extension functionality.Can anyone help me to write code to stop extension or stop execution of background.js