chrome和edge无法加载跨源源Map

dgjrabp2  于 2023-06-27  发布在  Go
关注(0)|答案(1)|浏览(277)

我想启动GWT SuperDevMode并在Chrome或Edge的DevTools上设置断点,但以前我可以查看源代码并设置断点。但是,由于最近的浏览器更新,因此不会显示源。
用于本地启动

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

所以这是一个跨源的问题,但是当我用Chrome的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

在控制台中显示为警告。
但是,源Map规范是

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

因此,端口规范似乎被浏览器强制重写(9876->8888)。
这种行为是否是由于安全增强造成的?或者只是一个bug?

wkftcu5l

wkftcu5l1#

此问题出现在GWT2.6.1中,可能已在后续版本中得到解决。为了处理GWT2.6.1,JettyLauncher.java在gwt-dev.jar中定制www.example.com,通过Filter为8888端口的源Map请求检索并返回9999端口的源,并将该类添加到project中,将其放在src中使用即可处理。

com.google.gwt.dev.shell.jetty.JettyLauncher.java(custom.添加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.新类)

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
    }

}

相关问题