1

im getting the above error. this is part of a chrome extension I made, but not sure how to fix this. Can someone pls help

  if (showConnection) {
    const speed = navigator.connection.downlink

    const connection = navigator.onLine
      ? (speed === 10 ? '> ' + speed : '~' + speed) + ' Mbps'
      : 'Offline'

    status += connection
  }

1 Answer 1

0

@bread : Here , navigator.connection is undefined, You can add optional chaining operator as below -

navigator?.connection?.downlink

But you need to check why is it undefined and skip the entire block if its not defined. Please modify your if condition as below :

if (showConnection && navigator?.connection) {

const speed = navigator?.connection?.downlink

    const connection = navigator.onLine
      ? (speed === 10 ? '> ' + speed : '~' + speed) + ' Mbps'
      : 'Offline'

    status += connection
}
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .