Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Invoking native print dialog causes cross domain issues

    I am using GWT 2.4 and SmartGWT 3.0 nightly (06/25/12) and have the following issue.

    When I invoke the native print dialog with the print layout, it works fine locally in dev mode on my machine, however when deployed to our dev servers, the native print dialog doesn't appear.

    Code:
    final List<Canvas> components = new ArrayList<Canvas>();
    		components.add(getPrintLayout());
    Canvas.printComponents(components.toArray());
    Here are the errors from Chrome console:
    Code:
    1.	Unsafe JavaScript attempt to access frame with URL [app url] from frame with URL http://[app url2]/sc/system/helpers/printFrame.html?id=isc_PrintCanvas_0&title=. The frame requesting access set 'document.domain' to 'com', but the frame being accessed did not. Both must set 'document.domain' to the same value to allow access. printFrame.html:40
    1.	Unsafe JavaScript attempt to access frame with URL [app url]from frame with URL http://[app url2]/sc/system/helpers/printFrame.html?id=isc_PrintCanvas_0&title=. The frame requesting access set 'document.domain' to 'com', but the frame being accessed did not. Both must set 'document.domain' to the same value to allow access. printFrame.html:53
    1.	Uncaught ReferenceError: params is not defined printFrame.html:63
    
    if (window.parent && window.parent.isc) {
     Unsafe JavaScript attempt to access frame with URL http://[app url] from frame with URL http://[app url2]/sc/system/helpers/printFrame.html?id=isc_PrintCanvas_0&title=. The frame requesting access set 'document.domain' to 'com', but the frame being accessed did not. Both must set 'document.domain' to the same value to allow access.
    
        // Page title, and print target ID are driven by parameters to this page.
        // We may not have a java server, so use the client-side getParams method to pick these up
        window.params = window.parent.isc.getParams(window);
    
        // Write out the title so we print with the appropriate title
        if (params.title) document.write("<TITLE>" + params.title + "</TITLE>");
    }
    Most likely the issue is here (document.domain.):
    Code:
    if (!window.isc && (window.opener != null || window.top != window)) {
        while (document.domain.indexOf(".") != -1) {
            try {
                // >IDocument
                // This attempt to reference a resource in another domain does not fail in certain 
                // modern browsers (Safari, Chrome) because there seems to be a more liberal 
                // interpretation of the same origin policy going on.  So, the flow here now is:
                // - The reference to window.opener.isc will fail with a security exception in 
                //   some browsers, and thus drop into the catch
                // - In other browsers, we will not get the security exception, but window.opener.isc
                //   will be undef, which also tells us we've got a domain mismatch
                // <IDocument
                if (window.opener.isc === undefined) {
                    try {
                        document.domain = document.domain.replace(/.*?\./, '');
                    } catch (ee) {
                        break;
                    }
                } else {
                    break;
                }
            } catch (e) {
                try {
                    document.domain = document.domain.replace(/.*?\./, '');
                } catch (ee) {
                    break;
                }
            }
        } 
    }

    #2
    We've tried to reproduce the issue you mention by running a recent version of 3.0p (from 2013-02-14 specifically) on one machine, and then hitting that server from another machine on the LAN, using a host file entry to allow it to be accessed as by name (e.g. one.two.three.com:8080), and we don't see any issue in Chrome version 25.0.1364.97 m.

    When we add a print button to one of the showcase samples, the preview dialog launches and we're able to see the preview just fine.

    Can you try updating to a current version of 3.0p, and provide some more details as to Chrome version, OS, and the domain name you're trying to access?

    Comment


      #3
      This is happening for all browsers (IE 9, FireFox 14 and Chrome 25). The issue is when we bypass the print preview, and invoke the native printer dialog with contents using Canvas.printComponents(components.toArray());

      Comment


        #4
        Can you also confirm whether you're still seeing this with a recent 3.0p nightly build.

        Thanks

        Comment

        Working...
        X