RocketChat / RocketChat/Rocket.Chat

Livechat WIdget API error in pageVisited Method

Open
#26,902 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: bug
Dominant language
TypeScript
Stars
46.1k
Forks
13.9k
Avg merge
3d 3h
Merged PRs (30d)
130

Description

Description:

pageVisited() API method fires on page load but throw a TypeError since rid is not defined if there is not yet an existing chat.

hooks.js:37 Uncaught TypeError: Cannot read properties of null (reading '_id')
    at pageVisited (hooks.js:37:26)
    at Hn (hooks.js:185:23)

Relevant code:

pageVisited(info) {
	if (info.change === 'url') {
		Triggers.processRequest(info);
	}

	const { token, room: { _id: rid } = {} } = store.state;
	const { change, title, location: { href } } = info;

	Livechat.sendVisitorNavigation({ token, rid, pageInfo: { change, title, location: { href } } });
}
Steps to reproduce:
  1. Copy / Paste livechat widget js onto a webpage.
  2. Load the page.
Expected behavior:

In the past pageVisted() would fire on page load and when a customer initiates a new chat, the chat agent can see the originating page.

Actual behavior:

Now this code is broken so livechat agent can't see the url of the page where chat is initiated unless the customer navigates after a chat has been created.

Server Setup Information:
  • Version of Rocket.Chat Server: 5.1.2
  • Operating System: Ubuntu 20.04.5
  • Deployment Method: Manual
  • Number of Running Instances: 1
  • DB Replicaset Oplog: n/a
  • NodeJS Version: 14.19.3
  • MongoDB Version: 5.0.12
Client Setup Information
  • Desktop App or Browser Version: n/a - applies to all tested browsers
  • Operating System: n/a - applies to all

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in hooks.js at the pageVisited entry point and reproduce the widget loading before a chat exists. Trace the store state and Livechat.sendVisitorNavigation call; done means page load no longer throws a TypeError and the originating page remains visible to the agent when a chat is initiated.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.