FF4/JetPack 上的 HTML5 画布绘制窗口错误
我借用了thumbnail.js 的代码对其进行了修改,以便它可以截取整个页面的屏幕截图(至少是这个想法),
Code:
function takeScreenshot(window) {
const { Cc, Ci, Cu } = require("chrome");
const AppShellService = Cc["@mozilla.org/appshell/appShellService;1"].
getService(Ci.nsIAppShellService);
var ss = AppShellService.hiddenDOMWindow.document
.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
ss.mozOpaque = true;
ss.width = window.innerWidth;
ss.height = window.innerHeight;
var ctx = ss.getContext("2d");
ctx.drawWindow(window, 0, 0, 500, 500, "rgb(255,255,255)"); // here is line 18 - where the error occured
return ss.toDataURL();
}
但我收到了一个错误......
Code:
Traceback (most recent call last):
File "resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-api-utils-lib/timer.js", line 64, in notifyOnTimeout
this._callback.apply(null, this._params);
File "resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-api-utils-lib/content/worker.js", line 64, in emitter
emit.apply(scope, params);
File "resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-api-utils-lib/events.js", line 147, in _emit
return this._emitOnObject.apply(this, args);
File "resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-api-utils-lib/events.js", line 177, in _emitOnObject
listener.apply(targetObj, params);
File "resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-addon-kit-lib/context-menu.js", line 609, in workerOnMessage
item.onMessage(msg);see error
File "resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-what-inspires-me-lib/main.js", line 27, in null
var imgdata = takeScreenshot(tabs.activeTab.window);
File "resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-what-inspires-me-lib/main.js", line 18, in takeScreenshot
ctx.drawWindow(window, 0, 0, 500, 500, "rgb(255,255,255)");
[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMCanvasRenderingContext2D.draw
Window]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: resource://jid0-qpxlmo42unizthqqbyuvdj
hd59y-api-utils-lib/securable-module.js -> resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-what-inspires-me-lib/main.j
s :: takeScreenshot :: line 18" data: no]
问题是什么?
I borrowed code from thumbnail.js modified it so that it takes screenshot of the entire page (at least thats the idea)
Code:
function takeScreenshot(window) {
const { Cc, Ci, Cu } = require("chrome");
const AppShellService = Cc["@mozilla.org/appshell/appShellService;1"].
getService(Ci.nsIAppShellService);
var ss = AppShellService.hiddenDOMWindow.document
.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
ss.mozOpaque = true;
ss.width = window.innerWidth;
ss.height = window.innerHeight;
var ctx = ss.getContext("2d");
ctx.drawWindow(window, 0, 0, 500, 500, "rgb(255,255,255)"); // here is line 18 - where the error occured
return ss.toDataURL();
}
but I got an error ...
Code:
Traceback (most recent call last):
File "resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-api-utils-lib/timer.js", line 64, in notifyOnTimeout
this._callback.apply(null, this._params);
File "resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-api-utils-lib/content/worker.js", line 64, in emitter
emit.apply(scope, params);
File "resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-api-utils-lib/events.js", line 147, in _emit
return this._emitOnObject.apply(this, args);
File "resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-api-utils-lib/events.js", line 177, in _emitOnObject
listener.apply(targetObj, params);
File "resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-addon-kit-lib/context-menu.js", line 609, in workerOnMessage
item.onMessage(msg);see error
File "resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-what-inspires-me-lib/main.js", line 27, in null
var imgdata = takeScreenshot(tabs.activeTab.window);
File "resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-what-inspires-me-lib/main.js", line 18, in takeScreenshot
ctx.drawWindow(window, 0, 0, 500, 500, "rgb(255,255,255)");
[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMCanvasRenderingContext2D.draw
Window]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: resource://jid0-qpxlmo42unizthqqbyuvdj
hd59y-api-utils-lib/securable-module.js -> resource://jid0-qpxlmo42unizthqqbyuvdjhd59y-what-inspires-me-lib/main.j
s :: takeScreenshot :: line 18" data: no]
whats the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能太旧了,但以防万一其他人偶然发现这一点。以下代码适用于 FF 3.0 至 FF 6 Beta
This is likely far too old, but in case somebody else stumbles on this. The following code works for me on FF 3.0 up to FF 6 Beta