{"id":26280084,"url":"https://github.com/kristofferstrube/blazor.serviceworker","last_synced_at":"2025-05-07T03:04:31.195Z","repository":{"id":63140421,"uuid":"565487702","full_name":"KristofferStrube/Blazor.ServiceWorker","owner":"KristofferStrube","description":"A Blazor wrapper for the Service Worker API.","archived":false,"fork":false,"pushed_at":"2024-08-04T10:12:57.000Z","size":10728,"stargazers_count":32,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-07T03:04:21.134Z","etag":null,"topics":["blazor","blazor-webassembly","csharp","fetch","github-pages","jsinterop","service","service-worker","serviceworker","serviceworkers","wasm","worker","wrapper"],"latest_commit_sha":null,"homepage":"https://kristofferstrube.github.io/Blazor.ServiceWorker/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KristofferStrube.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-13T15:14:05.000Z","updated_at":"2024-10-22T09:12:10.000Z","dependencies_parsed_at":"2023-11-28T23:40:12.291Z","dependency_job_id":null,"html_url":"https://github.com/KristofferStrube/Blazor.ServiceWorker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KristofferStrube%2FBlazor.ServiceWorker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KristofferStrube%2FBlazor.ServiceWorker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KristofferStrube%2FBlazor.ServiceWorker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KristofferStrube%2FBlazor.ServiceWorker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KristofferStrube","download_url":"https://codeload.github.com/KristofferStrube/Blazor.ServiceWorker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252804206,"owners_count":21806769,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blazor","blazor-webassembly","csharp","fetch","github-pages","jsinterop","service","service-worker","serviceworker","serviceworkers","wasm","worker","wrapper"],"created_at":"2025-03-14T14:18:36.538Z","updated_at":"2025-05-07T03:04:31.175Z","avatar_url":"https://github.com/KristofferStrube.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](/LICENSE.md)\n[![GitHub issues](https://img.shields.io/github/issues/KristofferStrube/Blazor.ServiceWorker)](https://github.com/KristofferStrube/Blazor.ServiceWorker/issues)\n[![GitHub forks](https://img.shields.io/github/forks/KristofferStrube/Blazor.ServiceWorker)](https://github.com/KristofferStrube/Blazor.ServiceWorker/network/members)\n[![GitHub stars](https://img.shields.io/github/stars/KristofferStrube/Blazor.ServiceWorker)](https://github.com/KristofferStrube/Blazor.ServiceWorker/stargazers)\n\n\u003c!-- [![NuGet Downloads (official NuGet)](https://img.shields.io/nuget/dt/KristofferStrube.Blazor.ServiceWorker?label=NuGet%20Downloads)](https://www.nuget.org/packages/KristofferStrube.Blazor.ServiceWorker/) --\u003e\n\n# Introduction\nA Blazor wrapper for the [Service Workers](https://www.w3.org/TR/service-workers/) API.\n\nThe API makes it possible to interact with and register a Service Worker that can control the fetching of resources for the website before any other contexts exist. This enables developers to make Progressive Web Apps (PWA). This project implements a wrapper around the API for Blazor so that we can easily and safely interact with and create Service Workers.\n\n**This wrapper is still being developed, so support is very limited.**\n\n# Demo\nThe sample project can be demoed at https://kristofferstrube.github.io/Blazor.ServiceWorker/\n\nOn each page you can find the corresponding code for the example in the top right corner.\n\nOn the [API Coverage Status](https://kristofferstrube.github.io/Blazor.ServiceWorker/Status) page you can get an overview over what parts of the API we support currently.\n\n# Getting Started\nA limitation of statically served Service Workers is that they only have access to the scope that the actual file belong in.\nSo we need to place the Service Worker interop bootstrapper in the root of our project. You can find that [here](https://github.com/KristofferStrube/Blazor.ServiceWorker/blob/main/samples/KristofferStrube.Blazor.ServiceWorker.WasmExample/wwwroot/service-worker.js), but the content is pretty simple:\n```js\nimportScripts(\"_content/KristofferStrube.Blazor.ServiceWorker/KristofferStrube.Blazor.ServiceWorker.Script.js\")\n```\n\nThen once we have copied the script to the root of `wwwroot` in our project we can register a service worker like so:\n\n```csharp\nvar builder = WebAssemblyHostBuilder.CreateDefault(args);\n\n// other services added and root components configured\n\nbuilder.Services.AddNavigatorService();\n\nvar app = builder.Build();\n\nvar navigator = app.Services.GetRequiredService\u003cINavigatorService\u003e();\nvar serviceWorker = await navigator.GetServiceWorkerAsync();\nvar rootPath = \"\";\n\nawait serviceWorker.RegisterAsync(\"./service-worker.js\", rootPath, async (scope) =\u003e {\n    scope.OnActivate = async () =\u003e\n    {\n        Console.WriteLine(\"We will do something when activating!\");\n    };\n});\n```\n\n# Issues\nFeel free to open issues on the repository if you find any errors with the package or have wishes for features.\n\n# Related repositories\nThis project uses the *Blazor.FileAPI* to return rich Blob objects in certain scenarios.\n- https://github.com/KristofferStrube/Blazor.FileAPI\n\n# Related articles\nThis repository was build with inspiration and help from the following series of articles:\n\n- [How to communicate with Service Workers](https://felixgerschau.com/how-to-communicate-with-service-workers/)\n- [Wrapping JavaScript libraries in Blazor WebAssembly/WASM](https://blog.elmah.io/wrapping-javascript-libraries-in-blazor-webassembly-wasm/)\n- [Call anonymous C# functions from JS in Blazor WASM](https://blog.elmah.io/call-anonymous-c-functions-from-js-in-blazor-wasm/)\n- [Using JS Object References in Blazor WASM to wrap JS libraries](https://blog.elmah.io/using-js-object-references-in-blazor-wasm-to-wrap-js-libraries/)\n- [Blazor WASM 404 error and fix for GitHub Pages](https://blog.elmah.io/blazor-wasm-404-error-and-fix-for-github-pages/)\n- [How to fix Blazor WASM base path problems](https://blog.elmah.io/how-to-fix-blazor-wasm-base-path-problems/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristofferstrube%2Fblazor.serviceworker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkristofferstrube%2Fblazor.serviceworker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristofferstrube%2Fblazor.serviceworker/lists"}