service worker is javascript file that run every time.It keeps running even you
close the browser.Due to this we can send push notification,offline mode.
//Register our service worker in index.html
<script>
if('serviceWorker' in navigator){
window.addEventListener('load', ()=> {
//registering of serviceWorker.
navigator.serviceWorker('./serviceworker.js')
.then((reg)=> console.log("Success:", reg.scope));
.catch((err)=> console.log("Failure: ", err));
})}
<script>
everything ok then we will see Sucess: localhost:3000 in console of browser
//Step 1: Publish the Worker service
cd "Path to the Worker service project"
dotnet restore
dotnet publish -o PathToThePublishFolder
//Step 2: Deploy and start with sc utility
sc.exe create DemoWorker binpath= PathToThePublishFolderYourWorkerClassName.exe
sc.exe start YourWorkerClassName
//Step 3: Stop and delete with sc utility
sc.exe stop YourWorkerClassName
sc.exe delete YourWorkerClassName
const filter = {
url: [
{
urlMatches: 'https://www.google.com/',
},
],
};
chrome.webNavigation.onCompleted.addListener(() => {
console.info("The user has loaded my favorite website!");
}, filter);