Namespace: SpawnDev.SpawnJS.JSObjects
Source: JSObjects/ServiceWorkerRegistrationOptions.cs
MDN Reference: ServiceWorkerRegistrationOptions on MDN
Options used when registering a ServiceWorker via ServiceWorkerContainer.Register() https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#options
| Property | Type | Access | Description |
|---|---|---|---|
ServiceWorkerRegistrationOptions |
class |
get | Options used when registering a ServiceWorker via ServiceWorkerContainer.Register() https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#options |
Type |
string? |
get | |
UpdateViaCache |
string? |
get |
SpawnDev.SpawnJS Mapping Note: The JavaScript examples below show the standard Web API usage. In SpawnDev.SpawnJS, the same API is available with C# conventions:
- Properties and methods use PascalCase (e.g.,
readyStatebecomesReadyState)- Events use ActionEvent with
+=/-=(e.g.,addEventListener("click", fn)becomesOnClick += handler)- Async methods return
Task<T>instead ofPromise<T>- Objects should be disposed with
usingstatements- Access via
JS.Get<ServiceWorkerRegistrationOptions>(...)or constructornew ServiceWorkerRegistrationOptions(...)
if (typeof trustedTypes === "undefined")
trustedTypes = { createPolicy: (n, rules) => rules };const scriptAllowList = [
// Some list of allowed URLs
];
const policy = trustedTypes.createPolicy("script-url-policy", {
createScriptURL(input) {
if (scriptAllowList.includes(input)) {
return input; // allow the script
}
console.log(`Script not in scriptAllowList: ${input}`);
return ""; // Block the script
},
});// The potentially malicious string
// We won't be including untrustedScript in our scriptAllowList array
const untrustedScript = "https://evil.example.com/service_worker.js";
// Create a TrustedScriptURL instance using the policy
const trustedScriptURL = policy.createScriptURL(untrustedScript);