Add screenshot collecting server

This commit is contained in:
Niklas von Hertzen
2017-08-28 21:27:39 +08:00
parent 5dbb197a82
commit b75fd70042
9 changed files with 180 additions and 26 deletions

View File

@ -75,8 +75,15 @@ const testSVG = document => {
const testForeignObject = document => {
const img = new Image();
const canvas = document.createElement('canvas');
canvas.width = 1;
canvas.height = 1;
const ctx = canvas.getContext('2d');
img.src = `data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'><foreignObject><div></div></foreignObject></svg>`;
ctx.fillStyle = 'red';
ctx.fillRect(0, 0, 1, 1);
img.src = `data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'><foreignObject><img src="${encodeURIComponent(
canvas.toDataURL()
)}" /></foreignObject></svg>`;
return new Promise(resolve => {
const onload = () => {

View File

@ -18,6 +18,7 @@ import Color, {TRANSPARENT} from './Color';
export type Options = {
async: ?boolean,
allowTaint: ?boolean,
backgroundColor: string,
canvas: ?HTMLCanvasElement,
imageTimeout: number,
proxy: ?string,
@ -71,14 +72,18 @@ const html2canvas = (element: HTMLElement, config: Options): Promise<*> => {
const documentBackgroundColor = ownerDocument.documentElement
? new Color(getComputedStyle(ownerDocument.documentElement).backgroundColor)
: TRANSPARENT;
const bodyBackgroundColor = ownerDocument.body
? new Color(getComputedStyle(ownerDocument.body).backgroundColor)
: TRANSPARENT;
const backgroundColor =
element === ownerDocument.documentElement
? documentBackgroundColor.isTransparent()
? ownerDocument.body
? new Color(getComputedStyle(ownerDocument.body).backgroundColor)
: null
? bodyBackgroundColor.isTransparent()
? options.backgroundColor ? new Color(options.backgroundColor) : null
: bodyBackgroundColor
: documentBackgroundColor
: null;
: options.backgroundColor ? new Color(options.backgroundColor) : null;
// $FlowFixMe
const result = Feature.SUPPORT_FOREIGNOBJECT_DRAWING.then(