'use client' | |
import { useEffect } from 'react' | |
export function ServiceWorkers(): JSX.Element { | |
useEffect(() => { | |
if (typeof window === 'undefined') { | |
return | |
} | |
if ('serviceWorker' in navigator) { |
import { useSignal, signal, effect } from '@preact/signals'; | |
import { useLayoutEffect, useMemo, useRef } from 'preact/hooks'; | |
/** @template T @typedef {T extends (infer U)[] ? U : never} Items */ | |
/** @param {{ v, k?, f }} props */ | |
const Item = ({ v, k, f }) => f(v, k); | |
/** | |
* Like signal.value.map(fn), but doesn't re-render. |
import { signal, effect } from "@preact/signals-core"; | |
interface CustomStorage { | |
getItem(key: string): void; | |
setItem(key: string, value: string | null): void; | |
} | |
/** | |
* A version of signal() that persists and recalls its value in localStorage. | |
* |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Service-worker demo</title> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<script> | |
if ( "serviceWorker" in navigator ) { |
import { HTTPError } from 'ky' | |
async function getErrorBody (error) { | |
if (error instanceof HTTPError) return (await error.response.text()) | |
return String(error) | |
} | |
function getErrorMessage (error) { | |
if (error instanceof Error) return error.message | |
return String(error) |
import { Peer } from 'socket:peer' | |
import process from 'socket:process' | |
import Buffer from 'socket:buffer' | |
import fs from 'socket:fs' | |
window.onload = async () => { | |
const clusterId = '14ecd42...' // truncated, make your own clusterId | |
const publicKeyHex = 'c43c1ddd...' // truncated, make your own hex encoded key | |
const privateKeyHex = '46adc2f8e9077c72...' // truncated, make your own hex encoded key |
(function () { | |
"use strict"; | |
var cacheNameStatic = 'cloudinary-pwa-react-v2'; | |
var currentCacheNames = [ cacheNameStatic ]; | |
var cachedUrls = [ | |
// 3rd party CDN | |
'https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/css/materialize.min.css', |
This is a working example on how to store CryptoKey
s locally in your browser. We are able to save the objects, without serializing them. This means we can keep them not exportable (which might be more secure?? not sure what attack vectors this prevents).
To try out this example, first make sure you are in a browser that has support for async...await
and indexedDB (latest chrome canary with chrome://flags
"Enable Experimental Javascript" works). Load some page and copy and paste this code into the console. Then call encryptDataSaveKey()
. This will create a private/public key pair and encrypted some random data with the private key. Then save both of them. Now reload the page, copy in the code, and run loadKeyDecryptData()
. It will load the keys and encrypted data and decrypt it. You should see the same data logged both times.
const express = require('express'); | |
const { html, Component } = require('htm/preact'); | |
const renderToString = require('preact-render-to-string'); | |
class App extends Component { | |
render(props) { | |
return html` | |
<div class="app"> | |
<h1>This is an app</h1> | |
<p>Current server time: ${new Date + ''}</p> |