【发布时间】:2014-03-17 17:14:38
【问题描述】:
我正在尝试将网页加载到隐藏框架(sdk/frame/hidden-frame)中,然后呈现它的屏幕截图。我可以很好地获得屏幕截图,但框架大小不合适。使用如下代码渲染截图
var hiddenFrames = require("sdk/frame/hidden-frame");
let hiddenFrame = hiddenFrames.add(hiddenFrames.HiddenFrame({
onReady: function() {
this.element.contentWindow.location = "http://example.com";
let self = this;
this.element.addEventListener("DOMContentLoaded", function() {
var cnvs = self.element.contentDocument.createElement("canvas");
var width = self.element.contentDocument.body.clientHeight; //for some reason clientWidth is 0 for www.example.com
var height = self.element.contentDocument.body.clientHeight;
cnvs.width = width;
cnvs.height = height;
var ctx = cnvs.getContext("2d");
console.log(width+" "+height);
ctx.drawWindow(self.element.contentWindow, 0, 0, width, height, "rgb(255,255,255)");
console.log(cnvs.toDataURL());
}, true, true);
}
}));
我已经尝试过改变 iframe 的宽度和高度
this.element.width = "1600";
this.element.height = "900";
用resizeTo()改变element.contentWindow的大小,改变body的大小。他们似乎都没有影响最终的截图,看起来像
【问题讨论】:
-
如果 iframe 隐藏了为什么要调整它的大小。
-
这样截图就可以正常渲染了。
标签: javascript html firefox firefox-addon firefox-addon-sdk