Skip to content
This repository was archived by the owner on Nov 3, 2024. It is now read-only.
This repository was archived by the owner on Nov 3, 2024. It is now read-only.

Cannot read properties of null (reading 'getData') #69

@NazariiShvets

Description

@NazariiShvets

Hi, I'm using your library in my project
We have Sentry for monitoring, and recently we started to catch such issues

image

Issue itself is strange, as for Chrome 124.0.0 clipboardData API, according to can-i-use, is supported
I would assume this is custom security options selected by user, or any other strange setup

Anyway, I believe issue can be resolved by adding fallback for clipboardData to navigator.clipboard.readText(), in case clipboardData is unavailable. And adding try-catch block with empty string as fallback, in case API is unavailable for user

async function getPastedValue(e: ClipboardEvent<HTMLInputElement>) {
  try {
    if(e.clipboardData) {
      return e.clipboardData.getData('Text')
    }
    
    if(navigator.clipboard) {
      const pastedValue = await navigator.clipboard.readText();
      
      return pastedValue
    }
    
    return ''
  } catch(e) {
    return ''
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions