content-script-screenshot.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use strict';
  2. const {openPrivateWindow} = require('zombie/webbrowser');
  3. const {console} = require('zombie/zombie');
  4. console.log('Opening window...');
  5. openPrivateWindow('about:')
  6. .then(w => {
  7. console.log('doing screenshot...');
  8. w.screenshot().then(data => {
  9. w.uri = data;
  10. console.log('screenshot:', data);
  11. })
  12. /*
  13. w.runScript(function () {
  14. try {
  15. let left = 0, top = 0, width, height;
  16. const curX = window.scrollX, curY = window.scrollY;
  17. scrollTo(0, 0);
  18. width = window.innerWidth + window.scrollMaxX - window.scrollMinX;
  19. height = window.innerHeight + window.scrollMaxY - window.scrollMinY;
  20. const canvas = window.document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  21. const ctx = canvas.getContext('2d');
  22. const ratio = window.devicePixelRatio;
  23. canvas.width = width * ratio;
  24. canvas.height = height * ratio;
  25. ctx.scale(ratio, ratio);
  26. ctx.drawWindow(window, left, top, width, height, 'transparent');
  27. const dataURI = canvas.toDataURL('image/png', '');
  28. scrollTo(curX, curY);
  29. return dataURI;
  30. } catch (e) {
  31. console.error(e, e + '');
  32. }
  33. //console.log(typeof ctx.drawWindow);
  34. //alert(typeof ctx.drawWindow);
  35. //return typeof ctx.drawWindow;
  36. })
  37. .then(dataURI => {
  38. console.log('screenshot:', dataURI);
  39. w.close();
  40. })
  41. */
  42. .catch(e => {
  43. console.log(e, e + '');
  44. });
  45. });
  46. // vim: ts=4 noet ai