drawWindow() 与多进程 Firefox (e10s) 中断了吗?

drawWindow() broken with multiprocess Firefox (e10s)?

Firefox drawWindow()-Function expects as first parameter a XUL content-window as provided by the low-level api tab utils.

然而,随着 Firefox 引入多进程架构(代号为 electrolysis 或 e10s),通过低级 api 直接访问选项卡是 no longer possible. While there are compatibility shims available, it is explicitly stated that they do not support plattform APIs that expect DOM objects。 另一方面,drawWindow() 不能在内容脚本中使用,因为它是 "chrome only"

所以我的问题是:

  1. 如果我无法在 chrome 之外使用它并且无法在 chrome 中获取 contentWindow-object,我该如何使用 drawWindow()
  2. 让我的插件在多进程 Firefox 中截取网站截图的其他选项是什么?

我们目前的方法是基于on the answer to this SO question。但是它不适用于多进程 Firefox

使用 drawWindow() 的解决方案确实是使用框架脚本,正如 Noitidart 在评论中所建议的那样。我用于屏幕截图的框架脚本如下所示:

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);
}

它是从 chrome-script 调用的,函数如下:

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);
}

相关阅读: