+ Start a Discussion
Ron Mccrerey 20Ron Mccrerey 20 

Visualforce to Lightning Communication

I wrote the communication from Visual Force to Lightning Component as shown here:

It worked great in the sandbox environment with no problems.
But when I deployed to production I get the following error:
Uncaught DOMException: Blocked a frame with origin "https://domain Name.visual.force.com" from accessing a cross-origin frame.
    at window_blur (chrome-extension://ddaloccgjfibfpkalenodgehlhkgoahe/jslib/nuanria.FrameConnector.js:338:18)
Hi Ron

Without LockerService it is exactly the same as you have already observed.
The sole reason is the fact that visualforce pages are served from a different domain than Lightning Experience (holding your Lightning Component).
This is done by Salesforce on purpose and it's considered as a security feature. You can't turn it off.
Good news: there is an officially documented practice to overcome this frontier by using window.postMessage(). With that you can implement bidirectional communication between Visualforce and Lightning Components.
It is described in depth here: https://developer.salesforce.com/blogs/developer-relations/2017/01/lightning-visualforce-communication.html (http:// https://developer.salesforce.com/blogs/developer-relations/2017/01/lightning-visualforce-communication.html)
There is no need of making REST calls for communication between VF and Lightning or going back to server as crmprgdev describes.
window.postMessage() is also not affected by LockerService. In fact you can find in the documentation of LockerService that this Standard Javascipt API is even officially supported by LockerService:
That means all this works fine with v40.0 and chances are very good that it will work in future versions either.

Mark as resloved if it helps :) :)
Bhanu Prakash
visit ForceLearn.com​ (https://www.forcelearn.com)
Ron Mccrerey 20Ron Mccrerey 20
That is the question, I did exactly as you said and it worked in the Sandbox, but it did not work when I moved it to the Production environment.
Why? and how do I fix it.
Ron Mccrerey 20Ron Mccrerey 20
Problem solved by creating a new outbound change set from the sandbox and deploying the new change set in production.