Giter VIP home page Giter VIP logo

clipboard's Introduction

@extend-chrome/clipboard

@extend-chrome/clipboard

npm (scoped) GitHub last commit License TypeScript Declarations Included

Chrome Extension Tutorials on YouTube 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 MV2 Chrome extension contexts. It emulates the Clipboard API readText and writeText methods using document.execCommand.

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 @extend-chrome/clipboard

Add the permissions "clipboardRead" and/or "clipboardWrite" to your manifest.json. Remember, only request the permissions you need! For example, if your extension only reads the clipboard, only request "clipboardRead".

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

TypeScript Definitions

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

Usage

import { clipboard } from '@extend-chrome/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')
})

clipboard's People

Contributors

dependabot[bot] avatar jacksteamdev avatar tanatcu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.