-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormDataNetworkRequest.js
More file actions
157 lines (129 loc) · 4.55 KB
/
FormDataNetworkRequest.js
File metadata and controls
157 lines (129 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// ====================================
// Form Data & Network Request Logger
// ====================================
(function() {
'use strict';
let requestLog = [];
let formLog = [];
/**
* Intercept fetch requests
*/
const originalFetch = window.fetch;
window.fetch = function(...args) {
const [resource, config] = args;
const logEntry = {
timestamp: new Date().toISOString(),
method: config?.method || 'GET',
url: resource,
headers: config?.headers || {},
body: config?.body || null,
};
requestLog.push(logEntry);
console.log('📤 Fetch Request:', logEntry.method, logEntry.url);
if (logEntry.body) {
console.log('Body:', logEntry.body);
}
return originalFetch.apply(this, args)
.then(response => {
console.log('📥 Fetch Response:', response.status, logEntry.url);
return response;
});
};
/**
* Intercept XMLHttpRequest
*/
const originalXHROpen = XMLHttpRequest.prototype.open;
const originalXHRSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.open = function(method, url, ...rest) {
this._requestInfo = { method, url };
return originalXHROpen.apply(this, [method, url, ...rest]);
};
XMLHttpRequest.prototype.send = function(body) {
if (this._requestInfo) {
const logEntry = {
timestamp: new Date().toISOString(),
method: this._requestInfo.method,
url: this._requestInfo.url,
body: body,
};
requestLog.push(logEntry);
console.log('📤 XHR Request:', logEntry.method, logEntry.url);
if (body) console.log('Body:', body);
}
return originalXHRSend.apply(this, [body]);
};
/**
* Monitor form submissions
*/
document.addEventListener('submit', function(e) {
const form = e.target;
const formData = new FormData(form);
const data = {};
formData.forEach((value, key) => {
data[key] = value;
});
const logEntry = {
timestamp: new Date().toISOString(),
action: form.action,
method: form.method,
data: data,
};
formLog.push(logEntry);
console.group('📝 Form Submission');
console.log('Action:', logEntry.action);
console.log('Method:', logEntry.method);
console.log('Data:', logEntry.data);
console.groupEnd();
}, true);
/**
* View logged requests
*/
window.showRequestLog = function() {
console.group('📊 Request Log');
console.table(requestLog);
console.groupEnd();
return requestLog;
};
/**
* View logged form submissions
*/
window.showFormLog = function() {
console.group('📊 Form Submission Log');
console.table(formLog);
console.groupEnd();
return formLog;
};
/**
* Clear logs
*/
window.clearLogs = function() {
requestLog = [];
formLog = [];
console.log('✅ Logs cleared');
};
/**
* Find all forms and their fields
*/
window.findAllForms = function() {
const forms = document.querySelectorAll('form');
console.group('📝 Form Discovery');
console.log(`Found ${forms.length} form(s)\n`);
forms.forEach((form, index) => {
console.groupCollapsed(`Form ${index + 1}: ${form.action || '(no action)'}`);
console.log('Method:', form.method || 'GET');
console.log('Action:', form.action || window.location.href);
console.log('ID:', form.id || '(none)');
console.log('Name:', form.name || '(none)');
const inputs = form.querySelectorAll('input, textarea, select');
console.log(`\nFields (${inputs.length}):`);
inputs.forEach(input => {
console.log(` - ${input.name || input.id || '(unnamed)'} [${input.type || input.tagName}]`);
});
console.groupEnd();
});
console.groupEnd();
return forms;
};
console.log('✅ Request & Form Logger loaded!');
console.log('Commands: showRequestLog(), showFormLog(), findAllForms(), clearLogs()');
})();