nostr-dev-kit / ndk

Nostr Development Kit with outbox-model support
https://nostr-dev-kit.github.io/ndk/
MIT License
366 stars 99 forks source link

Can't use this library in Chrome Extensions #271

Open Czino opened 2 months ago

Czino commented 2 months ago

As mentioned in https://github.com/Morglod/tseep/issues/23 I encounter a runtime error which comes from the tseep library

EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval'".

    at bakeCollection (bake-collection.ts:116:34)
Czino commented 2 months ago

Quickfix is moving to eventemitter3 library (for now). I haven't tested if it is fully compatible but the functionality I need works so far.

...
  "overrides": {
    "@nostr-dev-kit/ndk": {
      "tseep": "npm:eventemitter3@5.0.1"
    }
  }
...
Morglod commented 2 months ago

I will add fallback for this case in nearest time

As a workaround for now it could be sandboxed or unsafe-eval in manifest

Morglod commented 1 month ago

Just added fallback and no-eval version in tseep

Change is pretty simple (fallback may take more bundle size, but safe version is still very fast):

// from
import { EventEmitter } from "tseep";

// to
import { EventEmitter } from "tseep/lib/ee-safe"; // no-eval version
import { EventEmitter } from "tseep/lib/fallback"; // auto switch if eval is restricted