<?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: Experience Builder Interceptor Help in ArcGIS Experience Builder Questions</title>
    <link>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-interceptor-help/m-p/1604040#M18356</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/93846"&gt;@MKa&lt;/a&gt;&amp;nbsp;, please try the following code snippet&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { moduleLoader } from 'jimu-core'

const [esriConfig] = await loadModules(['esri/config']);
esriConfig.request.interceptors.splice(0, 0, myInterceptor);&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 09 Apr 2025 01:49:30 GMT</pubDate>
    <dc:creator>QunSun</dc:creator>
    <dc:date>2025-04-09T01:49:30Z</dc:date>
    <item>
      <title>Experience Builder Interceptor Help</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-interceptor-help/m-p/1603329#M18316</link>
      <description>&lt;P&gt;I am trying to implement an interceptor in my Experience Builder 1.8 custom widget.&amp;nbsp; Upgrading to latest Experience builder custom install is not an option right now.&amp;nbsp; I need to intercept a url request and get json as the response and NOT pbf.&amp;nbsp; This will fix an error I have with EXB1.8 and Enterprise 11.4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have read and tried to implement an interceptor, but not able to get it to actually work?&amp;nbsp; Where in the Experience builder client code would I place this interceptor (file?) and/or what am I missing here.&amp;nbsp; Currently I am just putting this in my Widget.tsx file of my custom witdget and it never gets fired.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where do I put this in client directory?&amp;nbsp; Currently I have at&lt;/P&gt;&lt;P&gt;client/your-extenstions/widgets/CustomNavbar/src/runtime/widget.tsx&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import esriConfig from '@arcgis/core/config.js';

const myInterceptor = {
  before: function (params) {
      // Modify the request here
      console.log('Intercepted request:', params);
      return params;
  },
  after: function (response) {
      // Modify the response here
      console.log('Intercepted response:', response);
      return response;
  },
  error: function (error) {
      // Handle errors here
      console.log('Intercepted error:', error);
      return Promise.reject(error);
  }
};

esriConfig.request.interceptors.splice(0, 0, myInterceptor);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Apr 2025 16:57:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-interceptor-help/m-p/1603329#M18316</guid>
      <dc:creator>MKa</dc:creator>
      <dc:date>2025-04-07T16:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Experience Builder Interceptor Help</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-interceptor-help/m-p/1604040#M18356</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/93846"&gt;@MKa&lt;/a&gt;&amp;nbsp;, please try the following code snippet&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { moduleLoader } from 'jimu-core'

const [esriConfig] = await loadModules(['esri/config']);
esriConfig.request.interceptors.splice(0, 0, myInterceptor);&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 09 Apr 2025 01:49:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-interceptor-help/m-p/1604040#M18356</guid>
      <dc:creator>QunSun</dc:creator>
      <dc:date>2025-04-09T01:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: Experience Builder Interceptor Help</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-interceptor-help/m-p/1604365#M18386</link>
      <description>&lt;P&gt;That worked.&amp;nbsp; I added the code as a widget and added to an experience to intercept the query.f == 'pbf' with query.f = 'json'.&amp;nbsp; The only thing i don't understand is why I only had to do the intercept once, meaning it only hits the breakpoint on the first call.&amp;nbsp; All subsequent calls to same url don't reach the "before" breakpoint.&amp;nbsp; Anyways, this was the solution i was looking for.&amp;nbsp; Here is the test widget for others with this problem.&amp;nbsp; This was build with ExB 1.8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { moduleLoader } from 'jimu-core';
import React, { Component } from 'react';

class MyCustomWidget extends Component {
  render() {
    (async () =&amp;gt; {
        const [esriConfig] = await moduleLoader.loadModules(['esri/config']);
        console.log("loading esri/config:" + esriConfig);

        const myInterceptor = {            
            urls: [/\/server\/rest\/.*/],
            before: function (params) {
                //We intercept the pbf on the first call, All subsequent calls seem to follow the json rule, so after the first intercept this works
                if (params.requestOptions.query.f == 'pbf' &amp;amp;&amp;amp; params.requestOptions.query.resultType != 'tile') {
                    console.log('Intercepted request:', params);
                    console.log('esriConfig.request params.url = ' + params.url)
                    params.requestOptions.query.f = 'json';
                }
                else
                {
                    console.log('SKIPPED esriConfig.request params.url = ' + params.url)
                    console.log('SKIPPED params.requestOptions.query.f = pbf = ' + params.requestOptions.query.f )
                    console.log('SKIPPED params.requestOptions.query.resultType = ' + params.requestOptions.query.resultType)
                }
            }
        };
        esriConfig.request.interceptors.splice(0, 0, myInterceptor);

    })();

    return (
      &amp;lt;div&amp;gt;
        &amp;lt;h1&amp;gt;Interceptor Widget&amp;lt;/h1&amp;gt;
      &amp;lt;/div&amp;gt;
    );
  }
}

export default MyCustomWidget;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 19:50:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-interceptor-help/m-p/1604365#M18386</guid>
      <dc:creator>MKa</dc:creator>
      <dc:date>2025-04-09T19:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Experience Builder Interceptor Help</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-interceptor-help/m-p/1609426#M18672</link>
      <description>&lt;P&gt;I suspect a reason this is only caught once is because it's inside the render method inside an IIFE (async () =&amp;gt; {})&lt;BR /&gt;&lt;BR /&gt;Even though render is part of React that Exb Builds upon, it can be called multiple times during a lifecycle, But the interceptor is only being attached once (think about it, if it was attaching every time, would it fire multiple times once?), and depending on that timing,&amp;nbsp; the ArcGIS API may have already finish its important 'pbf' network call by the time your interceptor attaches.&lt;BR /&gt;&lt;BR /&gt;Exb also by design heavily caches layers and webmap resources,&amp;nbsp; So the interceptor is either:&lt;BR /&gt;&lt;BR /&gt;1. not actually being setup early enough in the process.&lt;BR /&gt;2. There is nothing to intercept because future requests may actually be local and not going back to the server (so its maybe not being seen as a network request, and wouldn't fire)&lt;BR /&gt;&lt;BR /&gt;Suggest moving the interceptor to ComponentDidMount&lt;BR /&gt;&lt;BR /&gt;Perhaps like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { moduleLoader } from 'jimu-core';
import React, { Component } from 'react';

class MyCustomWidget extends Component {
  async componentDidMount() {
    const [esriConfig] = await moduleLoader.loadModules(['esri/config']);
    console.log("loading esri/config:", esriConfig);

    const myInterceptor = {
      urls: [/\/server\/rest\/.*/],
      before: function (params) {
        if (params.requestOptions.query.f === 'pbf' &amp;amp;&amp;amp; params.requestOptions.query.resultType !== 'tile') {
          console.log('Intercepted request:', params);
          console.log('esriConfig.request params.url = ' + params.url)
          params.requestOptions.query.f = 'json';
        } else {
          console.log('SKIPPED esriConfig.request params.url = ' + params.url)
          console.log('SKIPPED params.requestOptions.query.f = pbf = ' + params.requestOptions.query.f)
          console.log('SKIPPED params.requestOptions.query.resultType = ' + params.requestOptions.query.resultType)
        }
      }
    };

    esriConfig.request.interceptors.splice(0, 0, myInterceptor);
  }

  render() {
    return (
      &amp;lt;div&amp;gt;
        &amp;lt;h1&amp;gt;Interceptor Widget&amp;lt;/h1&amp;gt;
      &amp;lt;/div&amp;gt;
    );
  }
}

export default MyCustomWidget;&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Otherwise, the only other idea I can think of is that this might belong, not at a Widget Level, but App Level, I'm not sure off hand the best way to even attempt that though &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Apr 2025 21:09:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/experience-builder-interceptor-help/m-p/1609426#M18672</guid>
      <dc:creator>TimWestern</dc:creator>
      <dc:date>2025-04-25T21:09:14Z</dc:date>
    </item>
  </channel>
</rss>

