1.0.1 • Published 9 years ago

chrome-ext-screen-capture v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

chrome-ext-screen-capture

Capture screen from a chrome extension

Installation

In your manifest.json file, include the following:

"permissions": ["tabs", "<all_urls>"],
"background": {
    "scripts": ["background.js"]
}

In your background page, put the following:

require('chrome-ext-screen-capture').backgroundPage()

In your content script, the following will return an img url:

var cesc = require('chrome-ext-screen-capture')

cesc.takeScreenshot(function (canvas) {
  /* You can use either a getBoundingClientRect() function or any individual jQuery object */
  var selection = document.getSelection().getRangeAt(0).getBoundingClientRect()
  var imgURL = cesc.renderPreview(selection, canvas, {padding: 20}).toDataURL('image/png')
  console.log('Check this out', imgURL)
})

Acknowledgments

Much of this code was originally sourced from Louis Li and his post.