chrome and edge can't load cross-origin sourcemap

223 views Asked by At

I wanted to launch GWT SuperDevMode and set breakpoints on Chrome or Edge's DevTools, but previously I was able to view the source and set breakpoints. However, the source is not displayed due to recent browser updates.

for local startup

Web container: http://127.0.0.1:8888/
souecemap: http://127.0.0.1:9876/

So it's a cross-origin, but when I check it with Chrome's DevTools,

DevTools failed to load source map: Could not load content for http://127.0.0.1:8888/sourcemaps/GwtModule/gwtSourceMap.json: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

is displayed in the console as a warning.

However, the source map specification is

//# sourceMappingURL=http://127.0.0.1:9876/sourcemaps/GwtModule/gwtSourceMap.json

It states. Therefore, it seems that the port specification is forcibly rewritten(9876->8888) by the browser.

Is this behavior due to security enhancements? Or is it just a bug?

1

There are 1 answers

0
powtok On

This issue was in GWT2.6.1 and may have been resolved in later versions. In order to deal with GWT2.6.1, customize JettyLauncher.java in gwt-dev.jar to retrieve and return port 9999 origin via Filter for sourcemap request of port 8888 origin, and add that class to project You can deal with it by placing it in src and using it.

com.google.gwt.dev.shell.jetty.JettyLauncher.java (custom. Added wac.addFilter() )

  protected JettyServletContainer createServletContainer(TreeLogger logger,
      File appRootDir, Server server, WebAppContext wac, int localPort) {
      wac.addFilter(SourcemapFilter.class, "/sourcemaps/GwtModule/gwtSourceMap.json", EnumSet.of(DispatcherType.INCLUDE,DispatcherType.REQUEST));
      return new JettyServletContainer(logger, server, wac, localPort, appRootDir);
  }

com.google.gwt.dev.shell.jetty.SourcemapFilter.java (custom. new class )

public class SourcemapFilter implements Filter {

    @SuppressWarnings("unused")
    @Override
    public void init(FilterConfig arg0) throws ServletException {
        // noop
    }

    @SuppressWarnings("unused")
    @Override
    public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) arg0;
        HttpServletResponse response = (HttpServletResponse) arg1;
        String proxyURL =
                "http://" + request.getServerName() + ":" + System.getProperty("gwt.codeserver.port") + request.getRequestURI();
        System.out.println("[Sourcemap proxy filter] proxyURL: " + proxyURL);
        URL url = new URL(proxyURL);
        InputStream is = url.openStream();
        int value;
        while ((value = is.read()) != -1) {
            response.getWriter().write(value);
        }
        is.close();
    }

    @Override
    public void destroy() {
        // noop
    }

}