Running Javascript Error

I am trying to run a piece of javascript and am getting an error. This code is supposed to create a widget url that I can then show in an iFrame. At the end, I am sending the url to a Javascript to Bubble element. I have included the error from the console log. Any idea what could be going on? I am not an expert on javascript so any help would be appreciated.

const crypto = require("crypto");
const url = require("url");

const KEY = "ASK...";
const SECRET = "JAD....";

const recipientEmail = "";
const recipientReferenceId = "";

const widgetBaseUrl = new url.URL("");
const querystring = new url.URLSearchParams({
  ts: Math.floor(new Date().getTime() / 1000),
  key: KEY,
  email: recipientEmail,
  refid: recipientReferenceId,
  hideEmail: "false", // optional parameter: if 'true', hides the email field
  roEmail: "false", // optional parameter: if 'true', renders the email field as Read Only
  // payoutMethods: "bank-transfer,paypal",   // optional parameter: filters the possible payout methods shown on the widget
  locale: "en", // optional parameter: ISO 639-1 language code, changes the language of the widget
  ** Adding address fields is optional, Used to easily populate
  ** the widget with default values.
  'addr.firstName': 'firstName',
  'addr.lastName': 'lastName',
  'addr.governmentId': 'governmentId',
  'addr.street1': 'street1',
  'addr.street2': 'street2',
  '': 'city',
  'addr.postalCode': 'postalCode',
  'addr.region': 'AL',
  '': 'US',
  ** Adding color fields is also optional, used to override the
  ** color settings set in the dashboard. Note that these overrides must
  ** be valid CSS compatible colors.
  'colors.heading': '#111111',
  'colors.inputText': '#222222',
  'colors.inputBorder': '#333333',
  'colors.text': '#555555',
  'colors.subText': '#666666',
  'colors.background': '#777777',
  'colors.primary': 'red',
  'colors.border': 'blue',
  'colors.success': '#AAAAAA',
  'colors.error': '#BBBBBB',
  'colors.warning': '#CCCCCC',
  .replace(/\+/g, "%20");

const hmac = crypto.createHmac("sha256", SECRET);

// Signature is only valid for 30 seconds
const signature = hmac.digest("hex"); = querystring + "&sign=" + signature;

// you can send the link to your view engine
const widgetLink = widgetBaseUrl.toString();


Open your browser console and check errors there. Welcome to web dev!

This might be “dependencies” related. I created a plugin where I needed to do the hmac signature.

I used the following code:

… in my main javascript

const express = require('express')
const bodyParser = require('body-parser')
const crypto = require('crypto')
const cors = require('cors')
const KJUR = require('jsrsasign')

… in the package.json section of my server-side action

    "dependencies": {
        "express": "latest",
        "body-parser": "latest",
        "cors": "latest",
        "jsrsasign": "latest"

Hopefully this gives you some ideas.

You’re just clowning around (both of you) unless you get MORE SPECIFIC about the context here.

Are you doing this client side? In an SSA?

Because in the former case none of this will work. In the latter case it may or may not work.

But neither of you have provided sufficient info to help.

Additionally, if you are working client side just open the goddamn console.

@keith :upside_down_face:

If you are executing the code on the client the first 2 lines are wrong.
You can access crypto on the window object, and you should use URL and URLSearchParams

If you are executing the code on the backend keep in mind that node-url was last updated 7 years ago, you should use URL on nodejs too.

I may not have been clear…I do not know javascript. This code was in the documentation for the service with which I need to integrate. It is supposed to generate a widget that is then displayed in an iFrame. I believe it is node.js from my googling of the error and will need a plugin created. That is above my skillset at this time and am willing to hire someone to do it. If you’re interested, send me a message. Thanks!

I sent you a message :slight_smile:

This topic was automatically closed after 70 days. New replies are no longer allowed.