Skip to content

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

Open
@dsafonov-grid

Description

@dsafonov-grid

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions