edabg / jsprintsetup

JSPrintSetup Firefox addon
Mozilla Public License 2.0
76 stars 39 forks source link

Error: unsupported scheme:about #35

Open rohandayal opened 7 years ago

rohandayal commented 7 years ago

Have started facing an error alert since the last 2 weeks (so not sure if this related to an update). Alert says "Error: unsupported scheme:about". Once the error is shown, pressing OK just pops it up again and again, and I have to force quit Firefox to get it working. Happens randomly after a few prints.

image

In terms of deployment, I have a hidden iframe on a page which I populate using content on an event (button press) and then print the iframe using "jsPrintSetup.printWindow(document.getElementsByTagName("iframe")[printtype].contentWindow);"

rohandayal commented 7 years ago

PS> Have added localhost in permissions list as suggested in https://github.com/edabg/jsprintsetup/issues/23, to no avail. Plus, the page to be printed is not local.

mitkola commented 7 years ago

Are you sure that at the time of calling print iframe is fully loaded and have src. The problem can be some sort of asynchronous behavior.

rohandayal commented 7 years ago

Yes - iframe src is defined and loaded. I use javascript to populate a div in the iframe before printing.

In fact, it works most of the time, and then gives this error.

mitkola commented 7 years ago

Can you provide sample code that reproduce the problem?

rohandayal commented 7 years ago

Including some code below. I'm not sure this will help replicate as it works most of the time, but randomly gives that error:

HTML: This is the iframe that is populated with content. I have set its dimensions to match the dimensions of the paper that we use. <iframe name="kotprintframe" id="kotprintframe" src="/assets/static/kotprintframe.html" style="visibility: hidden; position: fixed; top: 0px; right: 0px;"></iframe>

Javascript: This code is called when a button is pressed. Have only included one line for the variable thishtml - There's a bunch of code that creates the html that is put into the print frame.

var thishtml = "<table style='width: 100%; font-family: Arial, sans-serif; font-size: 10px;'>";
$('#kotprintframe').contents().find('#container').html(thishtml);
jsPrintSetup.clearSilentPrint();
jsPrintSetup.setOption('printSilent', 1);
jsPrintSetup.setShowPrintProgress(false);
jsPrintSetup.setPrinter(selectedprinter);
jsPrintSetup.definePaperSize(101, 101, "receipt", "receipt", "Receipt", 78, 20, jsPrintSetup.kPaperSizeMillimeters);
jsPrintSetup.setPaperSizeData(101);
jsPrintSetup.setOption('headerStrLeft', '');
jsPrintSetup.setOption('headerStrCenter', '');
jsPrintSetup.setOption('headerStrRight', '');
jsPrintSetup.setOption('footerStrLeft', '');
jsPrintSetup.setOption('footerStrCenter', '');
jsPrintSetup.setOption('footerStrRight', '');
jsPrintSetup.setOption('marginTop', 0);
jsPrintSetup.setOption('marginBottom', 0);
jsPrintSetup.setOption('marginLeft', 0);
jsPrintSetup.setOption('marginRight', 0);
jsPrintSetup.setOption('edgeTop', 0);
jsPrintSetup.setOption('edgeLeft', 0);
jsPrintSetup.setOption('edgeBottom', 0);
jsPrintSetup.setOption('edgeRight', 0);
jsPrintSetup.setOption('unwriteableMarginTop', 0);
jsPrintSetup.setOption('unwriteableMarginLeft', 2);
jsPrintSetup.setOption('unwriteableMarginBottom', 10);
jsPrintSetup.setOption('unwriteableMarginRight', 0);
jsPrintSetup.setOption('printBGColors', 1);
jsPrintSetup.printWindow(document.getElementsByTagName("iframe")[printtype].contentWindow);
var copy2 = window.setTimeout(function() {
    $('#kotprintframe').contents().find('#container').html(detailhtml);
    jsPrintSetup.printWindow(document.getElementsByTagName("iframe")[printtype].contentWindow);
}, 500);
mitkola commented 7 years ago

I think that the problem is synchronization. The print process is asynchronous, i.e. when you call jsPrintSetup.printWindow javascript flow continues while printing is in progress. You must be sure that about two tings:

  1. The DOM is completely loaded
  2. There is no print in progress while calling print. I recommend to do the following change.
    
    // var printtype = something that was set outsize
    var thishtml = "<table style='width: 100%; font-family: Arial, sans-serif; font-size: 10px;'>";

function doJSPrint() { jsPrintSetup.clearSilentPrint(); jsPrintSetup.setOption('printSilent', 1); jsPrintSetup.setShowPrintProgress(false); jsPrintSetup.setPrinter(selectedprinter); jsPrintSetup.definePaperSize(101, 101, "receipt", "receipt", "Receipt", 78, 20, jsPrintSetup.kPaperSizeMillimeters); jsPrintSetup.setPaperSizeData(101); jsPrintSetup.setOption('headerStrLeft', ''); jsPrintSetup.setOption('headerStrCenter', ''); jsPrintSetup.setOption('headerStrRight', ''); jsPrintSetup.setOption('footerStrLeft', ''); jsPrintSetup.setOption('footerStrCenter', ''); jsPrintSetup.setOption('footerStrRight', ''); jsPrintSetup.setOption('marginTop', 0); jsPrintSetup.setOption('marginBottom', 0); jsPrintSetup.setOption('marginLeft', 0); jsPrintSetup.setOption('marginRight', 0); jsPrintSetup.setOption('edgeTop', 0); jsPrintSetup.setOption('edgeLeft', 0); jsPrintSetup.setOption('edgeBottom', 0); jsPrintSetup.setOption('edgeRight', 0); jsPrintSetup.setOption('unwriteableMarginTop', 0); jsPrintSetup.setOption('unwriteableMarginLeft', 2); jsPrintSetup.setOption('unwriteableMarginBottom', 10); jsPrintSetup.setOption('unwriteableMarginRight', 0); jsPrintSetup.setOption('printBGColors', 1); jsPrintSetup.printWindow(document.getElementsByTagName("iframe")[printtype].contentWindow); }

function doPrint() { $('#kotprintframe').contents().find('#container').html(thishtml); doJSPrint(); window.setTimeout(function() { $('#kotprintframe').contents().find('#container').html(detailhtml); doJSPrint(); }, 1000); // give enough time to be sure that previous print was fully completed }