Skip to content Skip to sidebar Skip to footer

Electron Manipulate/intercept Webview Requests And Responses

I want to create an Electron app that will use webview to display 3rd party content. I would like to be able to intercept all requests and responses from this webview. Sometimes I

Solution 1:

I think you should look into The Protocol API. it works as a proxy internally. say you wanna the user open http://www.google.com and see content like you've been conned!.

const { protocol } = require("electron");

const content = newBuffer("you've been conned!");

protocol.interceptBufferProtocol("http", (request, result) => {
  if (request.url === "http://www.google.com")
    returnresult(content);
  ... // fetch other http protocol content and return to the electron
});

there's lots of work to do, comparing to the WebRequest API. but it's much simpler than a independent local proxy.

Solution 2:

To get the request body of any http network call made by your electron app:

session.defaultSession.webRequest.onBeforeSendHeaders(filter, (details, callback) => {
        if (details.uploadData) {
            const buffer = Array.from(details.uploadData)[0].bytes;
            console.log('Request body: ', buffer.toString());
        }
        callback(details);
      })

Post a Comment for "Electron Manipulate/intercept Webview Requests And Responses"