We get error in the console about too much recursion, so the refactored code could be:
if (!report.__custom_print_override) {
const original_get_filters_html_for_print = frappe.query_report.get_filters_html_for_print;
frappe.query_report.get_filters_html_for_print = function(print_settings) {
let applied_filters = original_get_filters_html_for_print.call(this, print_settings);
// Check if chart exists and append its SVG to the output
if (this.chart && this.chart.svg) {
const encode = svg => 'data:image/svg+xml;base64,' + btoa((new XMLSerializer()).serializeToString(svg));
applied_filters += `<hr><img alt="${__('Chart')}" src="${encode(this.chart.svg)}" />`;
}
return applied_filters;
};
// Mark that we've overridden the method to avoid doing it again
report.__custom_print_override = true;
}