I am trying to integrate MIT App Inventor in iFrame with and Educational product. I am facing the issue of blocked cross-origin frame.
com.google.gwt.core.client.JavaScriptException: (SecurityError) : Blocked a frame with origin "http://127.0.0.1:8888" from accessing a cross-origin frame.
App where I want to integrate within iframe's URL : 127.0.0.1:8000
MIT App Inventor URL: 127.0.0.1:8888
If anybody can help me how to allow cross origin request in GWT framework for MIT App Inventor.
I've tried creating the filter and add some header for allowing the cross origin request as mentioned here : https://code.google.com/archive/p/gwtquery/wikis/Ajax.wiki
private static final String ALLOWED_DOMAINS_REGEXP = ". ";
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) servletRequest;
HttpServletResponse resp = (HttpServletResponse) servletResponse;
String origin = req.getHeader("Origin");
if (origin != null && origin.matches(ALLOWED_DOMAINS_REGEXP)) {
resp.addHeader("Access-Control-Allow-Origin", origin);
if ("options".equalsIgnoreCase(req.getMethod())) {
resp.setHeader("Allow", "GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS");
if (origin != null) {
String headers = req.getHeader("Access-Control-Request-Headers");
String method = req.getHeader("Access-Control-Request-Method");
resp.addHeader("Access-Control-Allow-Methods", method);
resp.addHeader("Access-Control-Allow-Headers", headers);
// optional, only needed if you want to allow cookies.
resp.addHeader("Access-Control-Allow-Credentials", "true");
resp.setContentType("text/plain");
}
resp.getWriter().flush();
return;
}
}
// Fix ios6 caching post requests
if ("post".equalsIgnoreCase(req.getMethod())) {
resp.addHeader("Cache-Control", "no-cache");
}
if (filterChain != null) {
filterChain.doFilter(req, resp);
}
}