1.0.5 • Published 6 years ago

@bumble/clipboard v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

npm (scoped) GitHub last commit License TypeScript Declarations Included

Fiverr: We make Chrome extensions ko-fi


Using the clipboard in a Chrome Extension can be a pain. The async Clipboard API doesn't work in background scripts and workarounds require lots of boilerplate. This library works in all Chrome extension contexts. It emulates the Clipboard API readText and writeText methods.

Table of Contents

Getting started

You will need to use a bundler like Rollup or Webpack to include this library in the build of Chrome extension.

See rollup-plugin-chrome-extension for an easy way use Rollup to build your Chrome extension!

Installation

$ npm i @bumble/clipboard

Add the permissions "clipboardRead" and/or "clipboardWrite" to your manifest.json.

{
  "permissions": ["clipboardRead", "clipboardWrite"]
}

Usage

import { clipboard } from '@bumble/clipboard'

// Read text from the clipboard, or "paste"
clipboard.readText()
  .then((text) => {
    console.log('clipboard contents', text)
  })

// Write text to the clipboard, or "copy"
clipboard.writeText('write this to the clipboard')
  .then((text) => {
    console.log(text, 'was written to the clipboard')
  })

Features

TypeScript Definitions

TypeScript definitions are included, so no need to install an additional @types library!

Notify on Copy

This library contains an extra function that creates a desktop notification when text has been copied, with a button to copy that text again.

This feature requires the "notifications" permission in your manifest.json.

It uses @bumble/notify, a Chrome extension notification library with a simpler API than chrome.notifications.

import { clipboard, notifyCopy } from '@bumble/clipboard'

// Write text to the clipboard
clipboard.writeText('copy this')
  // then create a copy notification
  .then(notifyCopy)
1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago