initFetchJs method

void initFetchJs()

Implementation

void initFetchJs() {
  controller.runJavaScript('''
                (function() {
                  // Intercept fetch API calls
                  const originalFetch = window.fetch;
                  window.fetch = function() {

                    FlutterChannel.postMessage(JSON.stringify(arguments));
                    return originalFetch.apply(this, arguments);
                  };

                  // Intercept XMLHttpRequest calls
                  const originalOpen = XMLHttpRequest.prototype.open;
                  XMLHttpRequest.prototype.open = function() {
                    FlutterChannel.postMessage(JSON.stringify(arguments));
                    return originalOpen.apply(this, arguments);
                  };
                })();
              ''');
}