wxt-dev/wxt

Use `navigator.clipboard` api but an error was reported "Cannot read properties of undefined"

Closed this issue · 2 comments

Describe the bug

I tried the navigator. clipboard.writeText and navigator. clipboard.write api, which work well in the IDE, but I encountered error during testing them

TypeError: Cannot read properties of undefined (reading 'writeText')
image image

Reproduction

minimal.zip

Steps to reproduce

pnpm i
wxt

System Info

System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 78.95 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.20.2 - ~/.nvm/versions/node/v18.20.2/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v18.20.2/bin/npm
    pnpm: 8.15.4 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 127.0.6533.89
    Safari: 17.4.1
  npmPackages:
    wxt: ^0.19.1 => 0.19.2

Used Package Manager

pnpm

Validations

@lapse12 Can't use clipboard API on the background script now. navigator.clipboard API doesn't exist.

So…you can exec on the browser(popup or content-scripts) or offscreen API or sendMessage hacks.

Some reference URLs are listed below.

I'm gonna close this as it's not an issue with WXT, but a question about how to use the clipboard API in general.