mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Fix logging option (#1302)
This commit is contained in:
parent
250208dc99
commit
d87fef11a4
@ -17,6 +17,7 @@ These are all of the available configuration options.
|
||||
| canvas | `null` | Existing `canvas` element to use as a base for drawing on
|
||||
| foreignObjectRendering | `false` | Whether to use ForeignObject rendering if the browser supports it
|
||||
| imageTimeout | `15000` | Timeout for loading an image (in milliseconds). Set to `0` to disable timeout.
|
||||
| logging | `true` | Enable logging for debug purposes
|
||||
| proxy | `null` | Url to the [proxy](/proxy/) which is to be used for loading cross-origin images. If left empty, cross-origin images won't be loaded.
|
||||
| removeContainer | `true` | Whether to cleanup the cloned DOM elements html2canvas creates temporarily
|
||||
| scale | `window.devicePixelRatio` | The scale to use for rendering. Defaults to the browsers device pixel ratio.
|
||||
|
@ -2,21 +2,23 @@
|
||||
'use strict';
|
||||
|
||||
export default class Logger {
|
||||
enabled: boolean;
|
||||
start: number;
|
||||
id: ?string;
|
||||
|
||||
constructor(id: ?string, start: ?number) {
|
||||
constructor(enabled: boolean, id: ?string, start: ?number) {
|
||||
this.enabled = enabled;
|
||||
this.start = start ? start : Date.now();
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
child(id: string) {
|
||||
return new Logger(id, this.start);
|
||||
return new Logger(this.enabled, id, this.start);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line flowtype/no-weak-types
|
||||
log(...args: any) {
|
||||
if (window.console && window.console.log) {
|
||||
if (this.enabled && window.console && window.console.log) {
|
||||
Function.prototype.bind
|
||||
.call(window.console.log, window.console)
|
||||
.apply(
|
||||
@ -31,7 +33,7 @@ export default class Logger {
|
||||
|
||||
// eslint-disable-next-line flowtype/no-weak-types
|
||||
error(...args: any) {
|
||||
if (window.console && window.console.error) {
|
||||
if (this.enabled && window.console && window.console.error) {
|
||||
Function.prototype.bind
|
||||
.call(window.console.error, window.console)
|
||||
.apply(
|
||||
|
@ -15,6 +15,7 @@ export type Options = {
|
||||
canvas: ?HTMLCanvasElement,
|
||||
foreignObjectRendering: boolean,
|
||||
imageTimeout: number,
|
||||
logging: boolean,
|
||||
proxy: ?string,
|
||||
removeContainer: ?boolean,
|
||||
scale: number,
|
||||
@ -37,7 +38,7 @@ const html2canvas = (element: HTMLElement, conf: ?Options): Promise<*> => {
|
||||
}
|
||||
|
||||
const config = conf || {};
|
||||
const logger = new Logger();
|
||||
const logger = new Logger(typeof config.logging === 'boolean' ? config.logging : true);
|
||||
|
||||
if (__DEV__ && typeof config.onrendered === 'function') {
|
||||
logger.error(
|
||||
|
Loading…
Reference in New Issue
Block a user