<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: WMSLayer Popup shows a sameorigin error in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/wmslayer-popup-shows-a-sameorigin-error/m-p/1521941#M85365</link>
    <description>&lt;P&gt;I seem to have answered my own question. For me, the key is to use the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-WMSLayer.html#fetchFeatureInfoFunction" target="_self"&gt;fetchFeatureInfoFunction&lt;/A&gt; function, and make a custom popup template there. I'm not sure if there's a better way to do this, definitely open to suggestions.&lt;BR /&gt;&lt;BR /&gt;In addition, I am not sure how long this wms source will be active for (this is a dev server that we are test driving Geoserver on). I will try to swap it out with another WMS layer that hopefully won't go away.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;See working code below:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8" /&amp;gt;
  &amp;lt;meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /&amp;gt;
  &amp;lt;title&amp;gt;WMSLayer | Sample | ArcGIS Maps SDK for JavaScript 4.30&amp;lt;/title&amp;gt;

  &amp;lt;style&amp;gt;
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  &amp;lt;/style&amp;gt;

  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.30/esri/themes/light/main.css" /&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.30/"&amp;gt;&amp;lt;/script&amp;gt;

  &amp;lt;script&amp;gt;
    require(["esri/Map", "esri/views/MapView", "esri/layers/WMSLayer", "esri/Graphic"], (Map, MapView, WMSLayer, Graphic) =&amp;gt; {

      const url = "https://geoserver225-ffmu3lsepa-uc.a.run.app/geoserver/public/ows";
      const sublayerName = "quaternaryfaults";

      const layer = new WMSLayer({
        url,
        sublayers: [{
          name: sublayerName,
          popupEnabled: true,
          queryable: true
        }],
        fetchFeatureInfoFunction: async (query) =&amp;gt; {
          console.log('running feature info func', layer);

          // Set info_format to request GeoJSON.
          query.info_format = "application/json";

          // Construct the URL for the feature info request.
          const featureInfoUrl = `${layer.featureInfoUrl}?${new URLSearchParams(query).toString()}`;
          
          try {
            const response = await fetch(featureInfoUrl);

            if (!response.ok) {
              throw new Error("Network response was not ok");
            }
            
            const data = await response.json();

            return data.features.map(
              (feature) =&amp;gt; new Graphic({
                attributes: feature.properties,
                popupTemplate: {
                  title: "Quaternary Faults {faultnum}",
                  content: [{
                    type: "fields",
                    fieldInfos: [
                      { fieldName: "label", label: "Description" },
                      { fieldName: "faultage", label: "Fault Age" },
                      { fieldName: "faultnum", label: "Fault Number" },
                      { fieldName: "qffhazardunit", label: "QFF Hazard Unit" },
                      { fieldName: "usgs_link", label: "USGS Link" },
                      { fieldName: "faultnum", label: "Fault Number" },
                    ]
                  }]
                }
              })
            );
          } catch (error) {
            console.error("Failed to fetch feature info:", error);
            return [];
          }
        }
      });

      const map = new Map({
        basemap: 'streets',
        layers: [layer]
      });

      const view = new MapView({
        container: "viewDiv",
        map: map,
        spatialReference: {
          wkid: 102100
        }
      });
    });
  &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Aug 2024 00:21:31 GMT</pubDate>
    <dc:creator>ClintonLunnUGS</dc:creator>
    <dc:date>2024-08-15T00:21:31Z</dc:date>
    <item>
      <title>WMSLayer Popup shows a sameorigin error</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/wmslayer-popup-shows-a-sameorigin-error/m-p/1520871#M85327</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Minimum example:&amp;nbsp;&lt;A href="https://codepen.io/clintonlunn/pen/eYweyzj?editors=1001" target="_blank"&gt;https://codepen.io/clintonlunn/pen/eYweyzj?editors=1001&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;I am trying to troubleshoot why I cannot get a popup working when I am pulling a WMS layer from Geoserver. When I click, the popup shows, but only an error message is populated. The console shows: "Refused to display '&lt;A href="https://geoserver225-ffmu3lsepa-uc.a.run.app/" target="_blank"&gt;https://geoserver225-ffmu3lsepa-uc.a.run.app/&lt;/A&gt;' in a frame because it set 'X-Frame-Options' to 'sameorigin'."&lt;BR /&gt;&lt;BR /&gt;When I copy the request into my api client tool (&lt;A href="https://www.usebruno.com/" target="_blank"&gt;https://www.usebruno.com/&lt;/A&gt;), I get the data back that I expect.&lt;/P&gt;&lt;P&gt;See working curl request below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;curl '&lt;A href="https://geoserver225-ffmu3lsepa-uc.a.run.app/geoserver/public/ows?bbox=-13716921.203505095%2C3336548.400852591%2C-10751100.402747236%2C6302369.20161045&amp;amp;crs=EPSG%3A3857&amp;amp;format=image%2Fpng&amp;amp;request=GetFeatureInfo&amp;amp;service=WMS&amp;amp;styles=&amp;amp;transparent=TRUE&amp;amp;version=1.3.0&amp;amp;layers=quaternaryfaults&amp;amp;query_layers=quaternaryfaults&amp;amp;info_format=text%2Fhtml&amp;amp;feature_count=25&amp;amp;width=3840&amp;amp;height=3840&amp;amp;I=1744&amp;amp;J=1887" target="_blank"&gt;https://geoserver225-ffmu3lsepa-uc.a.run.app/geoserver/public/ows?bbox=-13716921.203505095%2C3336548.400852591%2C-10751100.402747236%2C6302369.20161045&amp;amp;crs=EPSG%3A3857&amp;amp;format=image%2Fpng&amp;amp;request=GetFeatureInfo&amp;amp;service=WMS&amp;amp;styles=&amp;amp;transparent=TRUE&amp;amp;version=1.3.0&amp;amp;layers=quaternaryfaults&amp;amp;query_layers=quaternaryfaults&amp;amp;info_format=text%2Fhtml&amp;amp;feature_count=25&amp;amp;width=3840&amp;amp;height=3840&amp;amp;I=1744&amp;amp;J=1887&lt;/A&gt;' \&lt;BR /&gt;-H 'authority: geoserver225-ffmu3lsepa-uc.a.run.app' \&lt;BR /&gt;-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \&lt;BR /&gt;-H 'accept-language: en-US,en;q=0.9' \&lt;BR /&gt;-H 'referer: &lt;A href="https://cdpn.io/" target="_blank"&gt;https://cdpn.io/&lt;/A&gt;' \&lt;BR /&gt;-H 'sec-ch-ua: "Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"' \&lt;BR /&gt;-H 'sec-ch-ua-mobile: ?0' \&lt;BR /&gt;-H 'sec-ch-ua-platform: "macOS"' \&lt;BR /&gt;-H 'sec-fetch-dest: iframe' \&lt;BR /&gt;-H 'sec-fetch-mode: navigate' \&lt;BR /&gt;-H 'sec-fetch-site: cross-site' \&lt;BR /&gt;-H 'sec-fetch-user: ?1' \&lt;BR /&gt;-H 'upgrade-insecure-requests: 1' \&lt;BR /&gt;-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' \&lt;BR /&gt;--compressed&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ClintonLunnUGS_0-1723584762122.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/112255iDAED09E2FF4AF269/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ClintonLunnUGS_0-1723584762122.png" alt="ClintonLunnUGS_0-1723584762122.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Pasting code from the original snippet below:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8" /&amp;gt;
  &amp;lt;meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /&amp;gt;
  &amp;lt;title&amp;gt;WMSLayer | Sample | ArcGIS Maps SDK for JavaScript 4.25&amp;lt;/title&amp;gt;

  &amp;lt;style&amp;gt;
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  &amp;lt;/style&amp;gt;

  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.30/esri/themes/light/main.css" /&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.30/"&amp;gt;&amp;lt;/script&amp;gt;

  &amp;lt;script&amp;gt;
    require(["esri/Map", "esri/views/SceneView", "esri/layers/WMSLayer"], (
      Map,
      SceneView,
      WMSLayer,
    ) =&amp;gt; {
      const layer = new WMSLayer({
        url: "https://geoserver225-ffmu3lsepa-uc.a.run.app/geoserver/public/wms?",
        sublayers: [{
          name: "quaternaryfaults",
          queryable: true,
          popupEnabled: true
        }]
      });
      const map = new Map({
        basemap: 'streets',
        layers: [layer]
      });
      const view = new SceneView({
        container: "viewDiv",
        map: map,
        spatialReference: {
          wkid: 102100
        },
        center: [-110, 39.6949],
        zoom: 8
      });
    });
  &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 21:37:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/wmslayer-popup-shows-a-sameorigin-error/m-p/1520871#M85327</guid>
      <dc:creator>ClintonLunnUGS</dc:creator>
      <dc:date>2024-08-13T21:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: WMSLayer Popup shows a sameorigin error</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/wmslayer-popup-shows-a-sameorigin-error/m-p/1521941#M85365</link>
      <description>&lt;P&gt;I seem to have answered my own question. For me, the key is to use the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-WMSLayer.html#fetchFeatureInfoFunction" target="_self"&gt;fetchFeatureInfoFunction&lt;/A&gt; function, and make a custom popup template there. I'm not sure if there's a better way to do this, definitely open to suggestions.&lt;BR /&gt;&lt;BR /&gt;In addition, I am not sure how long this wms source will be active for (this is a dev server that we are test driving Geoserver on). I will try to swap it out with another WMS layer that hopefully won't go away.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;See working code below:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8" /&amp;gt;
  &amp;lt;meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /&amp;gt;
  &amp;lt;title&amp;gt;WMSLayer | Sample | ArcGIS Maps SDK for JavaScript 4.30&amp;lt;/title&amp;gt;

  &amp;lt;style&amp;gt;
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  &amp;lt;/style&amp;gt;

  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.30/esri/themes/light/main.css" /&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.30/"&amp;gt;&amp;lt;/script&amp;gt;

  &amp;lt;script&amp;gt;
    require(["esri/Map", "esri/views/MapView", "esri/layers/WMSLayer", "esri/Graphic"], (Map, MapView, WMSLayer, Graphic) =&amp;gt; {

      const url = "https://geoserver225-ffmu3lsepa-uc.a.run.app/geoserver/public/ows";
      const sublayerName = "quaternaryfaults";

      const layer = new WMSLayer({
        url,
        sublayers: [{
          name: sublayerName,
          popupEnabled: true,
          queryable: true
        }],
        fetchFeatureInfoFunction: async (query) =&amp;gt; {
          console.log('running feature info func', layer);

          // Set info_format to request GeoJSON.
          query.info_format = "application/json";

          // Construct the URL for the feature info request.
          const featureInfoUrl = `${layer.featureInfoUrl}?${new URLSearchParams(query).toString()}`;
          
          try {
            const response = await fetch(featureInfoUrl);

            if (!response.ok) {
              throw new Error("Network response was not ok");
            }
            
            const data = await response.json();

            return data.features.map(
              (feature) =&amp;gt; new Graphic({
                attributes: feature.properties,
                popupTemplate: {
                  title: "Quaternary Faults {faultnum}",
                  content: [{
                    type: "fields",
                    fieldInfos: [
                      { fieldName: "label", label: "Description" },
                      { fieldName: "faultage", label: "Fault Age" },
                      { fieldName: "faultnum", label: "Fault Number" },
                      { fieldName: "qffhazardunit", label: "QFF Hazard Unit" },
                      { fieldName: "usgs_link", label: "USGS Link" },
                      { fieldName: "faultnum", label: "Fault Number" },
                    ]
                  }]
                }
              })
            );
          } catch (error) {
            console.error("Failed to fetch feature info:", error);
            return [];
          }
        }
      });

      const map = new Map({
        basemap: 'streets',
        layers: [layer]
      });

      const view = new MapView({
        container: "viewDiv",
        map: map,
        spatialReference: {
          wkid: 102100
        }
      });
    });
  &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2024 00:21:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/wmslayer-popup-shows-a-sameorigin-error/m-p/1521941#M85365</guid>
      <dc:creator>ClintonLunnUGS</dc:creator>
      <dc:date>2024-08-15T00:21:31Z</dc:date>
    </item>
  </channel>
</rss>

