{"id":18246613,"url":"https://github.com/datvm/blazor.jsruntimeredirect","last_synced_at":"2025-09-04T00:07:27.134Z","repository":{"id":65148740,"uuid":"583744513","full_name":"datvm/Blazor.JsRuntimeRedirect","owner":"datvm","description":"A Blazor library to redirect _content JS request to a new one. Useful for Chrome Extension where _content folder is prohibited.","archived":false,"fork":false,"pushed_at":"2023-01-01T15:26:56.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-23T19:44:43.978Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/datvm.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-30T19:16:56.000Z","updated_at":"2023-04-13T17:40:39.000Z","dependencies_parsed_at":"2023-01-02T01:20:17.361Z","dependency_job_id":null,"html_url":"https://github.com/datvm/Blazor.JsRuntimeRedirect","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/datvm/Blazor.JsRuntimeRedirect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datvm%2FBlazor.JsRuntimeRedirect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datvm%2FBlazor.JsRuntimeRedirect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datvm%2FBlazor.JsRuntimeRedirect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datvm%2FBlazor.JsRuntimeRedirect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datvm","download_url":"https://codeload.github.com/datvm/Blazor.JsRuntimeRedirect/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datvm%2FBlazor.JsRuntimeRedirect/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273529572,"owners_count":25121831,"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","status":"online","status_checked_at":"2025-09-03T02:00:09.631Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-05T09:26:59.058Z","updated_at":"2025-09-04T00:07:27.079Z","avatar_url":"https://github.com/datvm.png","language":"C#","readme":"This project is an attempt to fix mingyaulee/Blazor.BrowserExtension#43 where Blazor for Chrome Extension cannot use Razor Class Library (RCL) assets due to `_content` being prohibited in Chrome Extension folders. It's also unlikely that there would be an official fix per dotnet/aspnetcore#45531.\n\nYou can also use this library as a custom interceptor for `IJsRuntime` that perform custom logic before calling `InvokeAsync`. It's recommended for Blazor WebAssembly only.\n\nSee [`Demo`](./Demo) folder for sample of a WebAssembly project as well as a Blazor Chrome Extension project using [mingyaulee/Blazor.BrowserExtension](https://github.com/mingyaulee/Blazor.BrowserExtension) and [KristofferStrube/Blazor.FileSystemAccess](https://github.com/KristofferStrube/Blazor.FileSystemAccess) RCL.\n\n# Installation \u0026 Setup\n\n## Nuget Package\n\nInstall this library through [Nuget package `Blazor.JsRuntimeRedirect`](https://www.nuget.org/packages/Blazor.JsRuntimeRedirect):\n\n```\ndotnet add package Blazor.JsRuntimeRedirect\n```\n\n## Setup Dependency Injection\n\nCall `AddJsRuntimeRedirect` to replace current implementation of `IJsRuntime` to the library's wrapper:\n\n```cs\nbuilder.Services\n    // Other services\n    .AddJsRuntimeRedirect();\n```\n\n\u003e **Warning**  \n\u003e `AddJsRuntimeRedirect` searches the current `IServiceCollection` for `IJsRuntime`'s `ImplementationInstance`. If there is none, exception would be thrown.\n\n`AddJsRuntimeRedirect` wraps the current `ImplementationInstance` of `IJsRuntime` to perform additional logic before calling their original methods.\n\n# Options\n\nBy default, the library attempt to redirect all `import` calls with `_content` in the path to `content`. This would solve mingyaulee/Blazor.BrowserExtension#43. You can override the settings using [Options pattern's `Configure`](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-7.0) or simply configure it with `AddJsRuntimeRedirect` method:\n\n```cs\nbuilder.Services\n    .AddJsRuntimeRedirect(options =\u003e\n    {\n        options.RedirectAfter = \"testcontent\";\n        options.RedirectIdentifiers = new(StringComparer.OrdinalIgnoreCase) { \"import\", };\n    });\n```\n\n- `ShouldRedirect` (default `true`): Whether the Redirect logic should be executed. `RedirectBefore`, `RedirectAfter`, `RedirectIdentifiers` are ignored if this is set to `false`. \n\n- `RedirectBefore` (default `_content`): the name of the path segment that should be replaced.\n\n- `RedirectAfter` (default `content`): the name of the path segment that should be replaced with.\n\n- `RedirectIdentifiers` (default `{ \"import\" }`): if set (non-`null`), the redirect logic is only considered if the `identifier` (i.e. the calling method, for example `import` or `alert`) is a value in the list. If set to `null`, every path is considered and therefore is not recommended due to performance impact.\n\n- `BeginInvokeJsInterceptor` (default `null`): A method that is called before any logic is executed. Here you can modify the values of `identifier` and `args`. If you set `Canceled` to `true`, the call would be terminated.\n\n\u003e **Note**  \n\u003e `BeginInvokeJsInterceptor` is called before `ShouldRedirect` logic. It's executed even if `ShouldRedirect` is `false`. However if you set `Canceled` to `true`, `ShouldRedirect` logic is not executed as the call is cancelled anyway.\n\nFrom the demo project, an example of using `BeginInvokeJsInterceptor` which replaces all `prompt` JS call into `alert` and cancel the call altogether if the first argument is `CancelThis`:\n\n```cs\noptions.BeginInvokeJsInterceptor = values =\u003e\n{\n    if (values.Identifier == \"prompt\")\n    {\n        if (values.Args?.FirstOrDefault() as string == \"CancelThis\")\n        {\n            values.Canceled = true;\n        }\n        else\n        {\n            values.Identifier = \"alert\";\n        }\n    }\n};\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatvm%2Fblazor.jsruntimeredirect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatvm%2Fblazor.jsruntimeredirect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatvm%2Fblazor.jsruntimeredirect/lists"}