使用drawWindow()的解決方案確實是使用framescripts作爲評論中建議的Noitidart。我用截圖的framescript看起來是這樣的:
addMessageListener("fs/make_screenshot_from_rectangle", makeScreenshot);
function makeScreenshot(payload) {
var rectangle = payload.data;
var startX = rectangle.startX || 0;
var startY = rectangle.startY || 0;
var width = rectangle.width || content.innerWidth;
var height = rectangle.height || content.innerHeight;
// Create canvas to draw window unto
var canvas = content.document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
canvas.width = width;
canvas.height = height;
// Create context for drawing, draw the old window unto the canvas
var context = canvas.getContext("2d");
context.drawWindow(content, startX, startY, width, height, "rgb(255,255,255)");
// Save context as png
var image = canvas.toDataURL('image/png');
sendAsyncMessage("got-screenshot", image);
}
並從具有以下功能的鍍鉻腳本調用:
function (rectangle) {
var tab = require("sdk/tabs").activeTab;
var xulTab = require("sdk/view/core").viewFor(tab);
var xulBrowser = require("sdk/tabs/utils").getBrowserForTab(xulTab);
var browserMM = xulBrowser.messageManager;
if (/* framescript not yet attached to tab */) {
browserMM.loadFrameScript(require("sdk/self").data.url("content-scripts/frame-script.js"), false);
... // do something to remember that there is a framescript attached to the tab
browserMM.addMessageListener("got-screenshot", function (payload) {
... // handle the screenshot
});
}
browserMM.sendAsyncMessage('fs/make_screenshot_from_rectangle', rectangle);
}
相關閱讀:
它肯定會從framecript工作。迫切需要一個可以處理幀的完整頁面截圖。即使內置的Firefox的節點截圖工具有時也會失敗。這是framescript的一個例子 - https://github.com/Noitidart/Full-Stop – Noitidart
我曾經假設framescripts和content-scripts是相同的,但顯然是錯誤的 - 是嗎? *嘆* 我現在將研究框架腳本,希望它能起作用。謝謝:) –
它非常不同,看看如何使用framescript的內容腳本看到這個插件 - https://github.com/Noitidart/Tweeeeeeeeeeeeeeeeeeeter – Noitidart