Skip to content
Meeko
Type to search the guides and the API reference. Open it from any page with / or Ctrl K; move with the arrow keys and open a result with Enter.
Get started

Contents

On this page

Not translated yet

This page has not been translated into English yet, so it is shown in Spanish.

inlineScriptHashes

función Since 1.3.0

Calcula el hash SHA-256 (base64) de cada <script> en línea de un documento HTML que el navegador comprueba con script-src: los de JavaScript, module, importmap y speculationrules. Los bloques de datos (application/json, application/ld+json, el payload de Meeko) y los scripts con src no cuentan. El texto se lee como lo hace el navegador, así que el hash coincide con el que comprueba.

ts
import { inlineScriptHashes } from "@meekojs/meeko/build";

Source code src/framework/script-hashes.ts:57

Firma #

ts
function inlineScriptHashes(html: string): InlineScriptReport

Parameters #

html string

Documento HTML completo.

Returns #

InlineScriptReport

Los hashes como fuentes CSP y el JavaScript que un hash no puede permitir.

Example #

ts
import { readFile } from "node:fs/promises";
import { inlineScriptHashes } from "@meekojs/meeko/build";
import { contentSecurityPolicy } from "@meekojs/meeko/server";

const { hashes, unhashable } = inlineScriptHashes(await readFile("dist/index.html", "utf8"));
if (unhashable.length) throw new Error(`JavaScript en línea sin hash: ${unhashable.join(", ")}`);
const header = contentSecurityPolicy({ "default-src": ["'self'"] }, hashes);

See also #

Was this page helpful?

Add a comment

It is sent when you choose “Yes” or “No”. Only the page, your answer and the comment are stored: no cookies and no personal data.

0 of 2000 characters

Edit on GitHub: packages/meeko/src/framework/script-hashes.ts