| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- const electron = require('electron')
- electron.contextBridge.exposeInMainWorld("electron", {
- ipcRenderer: electron.ipcRenderer,
- });
- // 拦截请求
- (function(xhr) {
- var XHR = XMLHttpRequest.prototype;
- var open = XHR.open;
- var send = XHR.send;
- var setRequestHeader = XHR.setRequestHeader;
- XHR.open = function(method, url) {
- this._method = method;
- this._url = url;
- this._requestHeaders = {};
- this._startTime = (new Date()).toISOString();
- return open.apply(this, arguments);
- };
- XHR.setRequestHeader = function(header, value) {
- this._requestHeaders[header] = value;
- return setRequestHeader.apply(this, arguments);
- };
- XHR.send = function(postData) {
- this.addEventListener('load', function() {
- var endTime = (new Date()).toISOString();
- var myUrl = this._url ? this._url.toLowerCase() : this._url;
- if(myUrl) {
- if (postData) {
- if (typeof postData === 'string') {
- try {
- // here you get the REQUEST HEADERS, in JSON format, so you can also use JSON.parse
- this._requestHeaders = postData;
- } catch(err) {
- console.log('Request Header JSON decode failed, transfer_encoding field could be base64');
- console.log(err);
- }
- } else if (typeof postData === 'object' || typeof postData === 'array' || typeof postData === 'number' || typeof postData === 'boolean') {
- // do something if you need
- }
- }
- // here you get the RESPONSE HEADERS
- var responseHeaders = this.getAllResponseHeaders();
- if ( this.responseType != 'blob' && this.responseText) {
- // responseText is string or null
- try {
- // here you get RESPONSE TEXT (BODY), in JSON format, so you can use JSON.parse
- var arr = this.responseText;
- // printing url, request headers, response headers, response body, to console
- // console.log(this._url);
- // console.log(JSON.parse(this._requestHeaders));
- // console.log(responseHeaders);
- // console.log(myUrl);
- if (window.owoHackUrl) {
- for (const key in window.owoHackUrl) {
- if (Object.hasOwnProperty.call(window.owoHackUrl, key)) {
- const element = window.owoHackUrl[key];
- if (myUrl.includes(key)) {
- if (element) element(arr)
- }
- }
- }
- }
- if (window.owoHackUrlSend) {
- for (const key in window.owoHackUrlSend) {
- if (Object.hasOwnProperty.call(window.owoHackUrlSend, key)) {
- const element = window.owoHackUrlSend[key];
- if (myUrl.includes(key)) {
- if (element) element(postData, myUrl)
- }
- }
- }
- }
- } catch(err) {
- console.log("Error in responseType try catch");
- console.log(err);
- }
- }
- }
- });
- return send.apply(this, arguments);
- };
- })(XMLHttpRequest);
|