This is an old thread but it is near the top of the search result listings, so I'm just going to put how to do it in here.
There are a number of posts online that mention passing the execution context to an onLoad event and then using contentwindow to call a method in the web resource with the formContext as a parameter.
I've tried this and the formContext is not always passed. Furthermore, navigating on to an entity on the related records tab and navigating back to the original tab causes the Web Resource to reload, but since the onLoad is not run when switching tabs, you need to run the same onLoad on change of tab. And again, it isn't always 100%.
The solution I've used .is to assign the formContext on the onLoad to a var on the top window. Simply do the following:
1: On your forms "onLoad" javascript webresource, put the following code in a function that is triggered on on load of the form (passing in formContext as first parameter):
window.top.formContextForXxxWebResource = executionContext.getFormContext();
2: Now in your HTML web resource, you can simply use the following object as the formContext!
window.top.formContextForXxxWebResource!
Why use window.top and not window.parent? I did use window.parent, but what if Microsoft change the product so that the web resource or the onload event have different parents? window.top will always be the same container, so this will ensures that you won't need to change it in future.
Hope this helps someone out there.