2

In my Developer Org, I am trying to use the code pertaining to displaying and hiding the Sidebar located here. This is my code (not too much different):

<apex:page >
    <apex:includeScript value="/support/console/39.0/integration.js"/>
    <script type="text/javascript">
        var callback = function (result) { 
            alert('Testing');
            if (result.success) { 
                alert('Congratulations!');
            }else { 
                alert('something is wrong!');
            }
        };
        function setSidebarVisible() {
            alert('Testing');
            var result = sforce.console.setSidebarVisible(true, callback);
        }
    </script>
    <button onClick="setSidebarVisible()">SetSidebarToExpand</button>
</apex:page>

However, I keep running into the following error:

Uncaught DOMException: Blocked a frame with origin "https://curious-goat-171067-dev-ed.my.salesforce.com" from accessing a cross-origin frame.
    at Object.handleOnload (https://curious-goat-171067-dev-ed.my.salesforce.com/support/console/xdomain/30.0/iframeinterface.js:1:356)
    at window.onload (https://curious-goat-171067-dev-ed.my.salesforce.com/support/console/xdomain/30.0/crossDomainProxy.html:4:89)

What exactly am I doing wrong? Or why am I being prevented from executing this code?

1 Answer 1

2

I found the following reference in Launching a Visual Force Page in the Service Cloud Console (my emphasis):

IMPORTANT: Be careful if your uses a visualforce inside another vf, for example using . The services console has one level of indirection between domains, so if you try to use console toolkit inside the iframe, you will get a javascript error because cross-site restrictions. To avoid the issue you have to call any function using the parent page, that's why we put a try-catch block in our function.
Same happends if you override a view's link and use a custom page with a , for example for cases. You will have a LOT of problems, because in that case the level of indirection is two. :smileysad:

This corresponds with the Salesforce Console Developer Guide - Best Practices:

The Salesforce Console Integration Toolkit methods don't work in nested iFrames. For example, when you embed a Visualforce page into a page layout or use a custom quick action in a feed, the API method works as expected. However, if Development Mode is enabled in your org, the API method doesn't work because an iFrame is automatically added.

It looks like you are in a Trailhead hands-on org. Try disabling Development Mode as a first step.

3
  • Thank you Daniel. I have disabled Development Mode for my User in two separate Dev Orgs and tried this, all to no avail. Maybe this is the nature of Dev Orgs generally?
    – Rooster
    Commented May 24, 2017 at 23:49
  • @Rooster check the iframe structure you are dealing with. It might also be related to the MyDomain setting. Something is isolating the code where your JavaScript is executing from the target iframe. Commented May 25, 2017 at 0:37
  • Thanks @Daniel. Sorry for my late response on this. It looks like my actual Domain is slightly different from the domain used in the API method. With a custom MyDomain, the URL changes and a '--c' is added to the end of my custom domain (for example: 'saggu18-dev-ed--c.na30.visual.force.com/apex/…). I suppose I am still trying to get around the iFrame issue.
    – Rooster
    Commented Jun 6, 2017 at 1:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .