Dino icon indicating copy to clipboard operation
Dino copied to clipboard

Bug: Off-by-one error in visuals.js link highlight removal

Open HRISHIKESH-hackoff opened this issue 10 months ago • 4 comments

Bug Description

In popup/visuals.js, there is an off-by-one error in the link highlight removal function. On line 20, the code loops through the links array instead of the removeLinkHighlight array:

const removeLinkHighlight = document.getElementsByClassName("remove-link-hg");
for (let i = 0; i < links.length; i++) {  // BUG: Should be removeLinkHighlight.length
  removeLinkHighlight[i].addEventListener('click', function (e) {

Impact

This causes only the first N elements to have the event listener attached (where N is the length of the links array). If there are more remove buttons than link buttons, the extra remove buttons won't have the event listener. Conversely, if there are fewer remove buttons, this could cause an index error.

Fix

Change line 20 from:

for (let i = 0; i < links.length; i++) {

To:

for (let i = 0; i < removeLinkHighlight.length; i++) {

Additional Improvements Identified

  1. Error handling in speech.js: The fetchMeaning() function doesn't handle cases where the API response doesn't have the expected structure. Should add validation for json[0].meanings[0].definitions[0].

  2. Memory leaks in zoom functionality: The zoom event listeners in visuals.js are attached every time, but they should be debounced or checked to prevent multiple listeners on the same element.

  3. Race conditions in extension permissions: The manifest.json requests broad permissions (<all_urls>). Consider limiting to specific domains or implementing dynamic permission requests.

  4. Missing null checks: Multiple files don't check if DOM elements exist before adding event listeners, which could throw errors on certain pages.

HRISHIKESH-hackoff avatar Feb 04 '26 11:02 HRISHIKESH-hackoff

@HRISHIKESH-hackoff I would like to fix this bug :)

SRUJAN-cpu avatar Feb 04 '26 16:02 SRUJAN-cpu

Hi 👋 I would like to work on this issue. Could you please assign it to me?

srija-pixel avatar Feb 20 '26 07:02 srija-pixel

Hi 👋 I would like to work on this issue. Please assign it to me. Thanks! 😊

vidya-0407 avatar Mar 11 '26 11:03 vidya-0407

Its an open issue now. You can go head

developer-diganta avatar Mar 11 '26 13:03 developer-diganta