Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Akamai EW doesnt have TextEncoder and crypto as Globals #925

Open
1 task done
dsafonov-grid opened this issue Apr 26, 2024 · 1 comment
Open
1 task done

Comments

@dsafonov-grid
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

SDK Version

5.3.0

Current Behavior

Running EW version as is, causing runtime Errors e.g.

Error crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported Error: crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported%0A at m (main.js:1:2041)%0A at C (main.js:1:2439)%0A at Object.uuid (main.js:1:7729)%0A at a.decisionObj (main.js:1:70858)%0A at e.sendImpressionEvent (main.js:1:71159)%0A at e.decide (main.js:1:86430)%0A at main.js:1:87419%0A at Array.forEach ()%0A at e.decideForKeys (main.js:1:87390)%0A at e.decideAll (main.js:$

and similar about TextEncoder

Expected Behavior

Everything happens without errors

Steps To Reproduce

  1. In https://github.com/optimizely/akamai-edgeworker-starter-kit with 5.3.0
  2. Use approach suggested in [BUG] Using client.createUserContext leads to setTimeout is not defined error on Akamai EdgeWorker #924 to proceed to next errors

SDK Type

Edge/Lite

Node Version

No response

Browsers impacted

No response

Link

No response

Logs

No response

Severity

No response

Workaround/Solution

Hi Optimizely Team,

As Per: https://techdocs.akamai.com/edgeworkers/docs/specifications

  1. the env in Akamai EW doesn't have TextEncoder used by murmurhash
    https://github.com/perezd/node-murmurhash/blob/master/murmurhash.js#L4
  2. the env in Akamai EW doesn't have crypto used by uuid https://github.com/uuidjs/uuid/blob/bc46e198ab06311a9d82d3c9c6222062dd27f760/src/rng-browser.js#L17

Would you consider a proper workaround doing this in main.ts

import { TextEncoder } from 'encoding';
import { crypto } from 'crypto';
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/ban-ts-comment
// @ts-ignore
globalThis.TextEncoder = TextEncoder;
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/ban-ts-comment
// @ts-ignore
globalThis.crypto = crypto;

Because for me this seem to be working fine

Recent Change

No response

Conflicts

No response

@mikechu-optimizely
Copy link
Contributor

Thanks. We're looking into a similar report at optimizely/react-sdk#232

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants