When trying to use the JavaScript SDK in my canvas app, I get the following error:

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://myapp.com') does not match the recipient window's origin ('https://c.eu0.visual.force.com/').

The method I'm trying to run is this:

Sfdc.canvas.client.resize(Sfdc.canvas.oauth.client(),  { width : '10%' });

Just for a bit of context, I try to run that after successfully authenticating via Force oAuth.

Any ideas?

1 Answer 1


I figured out what was causing my problem. When Salesforce loads a canvas app, it adds a hash fragment to the url that the SDK needs to communicate between the iframe and the parent window. My app was redirecting to handle oauth and the hash was getting lost in the process. I ended up making an initial page that has javascript in the head to take the hash and send it on as a url parameter, which I can give back to my app as a hash once again at the end. Hacky, but it seems to work.

UPDATE: After further inquiry, here's an example of what the page at the url you provide Salesforce might look like:

    <script>window.location.href = "www.myOauthSite.com?salesforceHash=" + encodeURIComponent(window.location.hash);</script>

And then you might, on www.myOauthSite.com, redirect back to your Salesforce canvas app by adding back on the salesforceHash parameter to the end of the url as the hash.

You must log in to answer this question.

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