New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 797534 link

Starred by 1 user

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , Windows , Mac
Pri: 2
Type: Bug


Show other hotlists

Hotlists containing this issue:
Hotlist-1


Sign in to add a comment

iframe printing using javascript brings blank page if url starts with https

Reported by rajsj1...@gmail.com, Dec 24 2017

Issue description

Chrome Version       : 63.0.3239.84
OS Version: 6.1 (Windows 7, Windows Server 2008 R2)
URLs (if applicable) : 
Other browsers tested:
  Add OK or FAIL after other browsers where you have tested this issue:
     Safari: NOT TESTED
    Firefox: WORKS CORRECTLY
    IE/Edge: WORKS CORRECTLY

What steps will reproduce the problem?

1. Go to below urls. Click on print link. 

http://mediateqindia.com/testPrint.html (works correctly)

https://mediateqindia.com/testPrint.html (blank page on click print link)

Both url pointing to same page.

2. Issue was replicable when loading this page in multiple webservers and testing from different PC with windows OS.

3. If clicked multiple time on print link , sometimes page works from second click onwards if url starts with https. If url starts with http, it is always working.

4. Page working correctly in IE and Firefox. Had to code to print like this as requirement was that, I could not use window.print or window.open functions to print.

What is the expected result?
data shown on page should be printed.

What happens instead of that?
Blank page when clicking print link for first time when url starts with https.

Please provide any additional information below. Attach a screenshot if
possible.

Full code that is used in "testPrint.html" whose url is provided above.

<pre>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bindddddddddd</title>
</head>
<body>
<div id="testPrintDiv" >
Hiiiiiiiiiiiiiii
<br /><br />
Hellooooooooooooo
<br /><br />
World !!!!!!!!!!!!!!!!!!!!!!!!!!!s
<a href="javascript:printTest();">Print</a>
</div>
</body>
</html>



<script>
function printTest(){
var scale=1;
var contents=document.getElementById("testPrintDiv").innerHTML;
if(!scale){ 
    scale=".9";
}
    var printframe = document.createElement('iframe');
    printframe.name = "printframe";
    printframe.style.position = "absolute";
    printframe.style.top = "-1000000px";
    document.body.appendChild(printframe);
    var frameDoc = printframe.contentWindow ? printframe.contentWindow : printframe.contentDocument.document ? printframe.contentDocument.document : printframe.contentDocument;
    frameDoc.document.open();
    frameDoc.document.write('<meta http-equiv="X-UA-Compatible" content="IE=edge" /><html><head><title></title>');
    frameDoc.document.write('<link rel="stylesheet" type="text/css" href="/user/data/css/styles-min.css">');
    frameDoc.document.write('<style type="text/css">@media print { body {transform: scale('+scale+');} @page{margin-left: 0cm;} body {margin-left:0;padding:0;}'
                +'</style></head><body>');
       frameDoc.document.write(contents);
        frameDoc.document.write('</body></html>');
       frameDoc.document.close();

       setTimeout(function () {
            window.frames["printframe"].focus(); 
            window.frames["printframe"].print();       
             setTimeout(function () {
                document.body.removeChild(printframe);
             },5000);
        }, 750);

    //return false;     
}

</script>
</pre>


 

Comment 1 by rajsj1...@gmail.com, Dec 24 2017

Please note <pre> tag is not part of html code . I added to format code, which as I see now is not required. Not sure how to edit it, so adding comment. If someone can kindly remove <pre></pre> tags to avoid confusion. 
Labels: Needs-Triage-M63
Cc: vamshi.k...@techmahindra.com
Components: Internals>Printing
Labels: -Pri-3 M-65 Triaged-ET OS-Linux OS-Mac Pri-2
Status: Untriaged (was: Unconfirmed)
Able to reproduce the issue on reported chrome version 63.0.3239.84 and on the latest canary 65.0.3305.0 using Windows 10, Ubuntu 14.04 and Mac 10.13.1. As the issue is seen from M52(52.0.2702.0) considering it as non-regression hence marking as UNtriaged.

Note: We are unable to check the issue on M50 an M51 as navigating to the URL https://mediateqindia.com/testPrint.html gives "clock error" .

Thanks!

Comment 4 by rajsj1...@gmail.com, Jan 13 2018

I think I found out the cause of this issue. Css file loading time is the most probable cause here. 

When I remove this line "frameDoc.document.write('<link rel="stylesheet" type="text/css" href="/user/data/css/styles-min.css">');" the printing works fine even if url is starting with http or https.

I worked around the issue by using ajax to fetch the contents of css file and then writing the content of file to this page using frameDoc.document.write('<style>' + contentOfCssFile + '</style>'); 

After the change the issue only occured once every 100 print icon clicks. Then I increased the setTimeout time and now the issue seems to be resolved.

Thanks to everybody who were part of this. I will leave the test files on the server for some more time . I am not sure if this is expected behaviour or a bug. Kindly close this issue if this will not be worked on.
Labels: Needs-Feedback
Has the test file changed since when the bug was filed? I tried just now and the HTTP and HTTPS versions of the site generates the same (not blank) print preview for me.

Also, the HTTPS version of the website has certificate issues.

Comment 6 by rajsj1...@gmail.com, Jan 24 2018

The files has not been changed since the issue was reported.

Like I mentioned first time itself

If clicked multiple time on print link , sometimes page works from second click onwards if url starts with https. If url starts with http, it is always working.

I am not sure but maybe the print works from second time because the style is fetched from cache. 

To test this always open the link(with https) in new tab and check if data is shown on print preview when print link is clicked the first time. To replicate again close the page and open link in new tab again.

I am able to still replicate the issue.

Certificate issue is becuase the server is self certified. I am using that server only for loading sample files. The original issue was faced in a server with valid certification.

Also like I mentioned in the comments, I was able to get print working even for https links. Please check above comments for details.
Labels: -Needs-Feedback
Owner: thestig@chromium.org
Status: Assigned (was: Untriaged)
Mac triage: assigning back to thestig@ since there's now feedback in #6.

Sign in to add a comment