-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
460 lines (404 loc) · 15.6 KB
/
index.html
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
<head>
<script>
window.__gCrWeb.common.isSameOrigin = function(a, c) {
return true;
}
/*window.__gCrWeb.passwords['fillPasswordForm'] = function(
formData, username, password, opt_normalizedOrigin) {
//alert(password)
var normalizedOrigin = opt_normalizedOrigin ||
__gCrWeb.common.removeQueryAndReferenceFromURL(window.location.href);
var origin = (formData['origin']);
if (!__gCrWeb.common.isSameOrigin(origin, normalizedOrigin)) {
return false;
}
return fillPasswordFormWithData_(
formData, username, password, window, opt_normalizedOrigin);
};*/
</script></head>
<style>
body {
font-size: 14px;
}
</style>
<div id = 'objs'></div>
<script>
var logDiv = document.getElementById('objs');
var filters = window.__gCrWeb;
for (i in filters){
for (key in filters[i]){
//log( key + ": " + filters[i][key]);
}
}
//window.__crWeb.chromeBundleMainFrame = null;
var obj = window.__gCrWeb.common;
//obj = obj.chromeBundleMainFrame;
while(obj){
for(let prop of Reflect.ownKeys(obj)){
//log(prop);
};
obj = Object.getPrototypeOf(obj);
};
for (var c = 0; c < 3000; c++) {
console.log(c);
}
//var sameOrigin = __gCrWeb.common.isSameOrigin("abc", "123");
//alert(sameOrigin)
//alert(window.__gCrWeb.common.removeQueryAndReferenceFromURL(window.location.href))
/*
var originalWindowHistoryPushState = window.history.pushState;
var originalWindowHistoryReplaceState = window.history.replaceState;
__gCrWeb['replaceWebViewURL'] = function(url, stateObject) {
originalWindowHistoryReplaceState.call(history, stateObject, '', url);
};
window.history.replaceState = function(stateObject, pageTitle, pageUrl) {
//alert(pageUrl);
__gCrWeb.message.invokeOnHost({'command': 'window.history.willChangeState'});
// Calling stringify() on undefined causes a JSON parse error.
var serializedState = typeof(stateObject) == 'undefined' ?
'' :
__gCrWeb.common.JSONStringify(stateObject);
pageUrl = pageUrl || window.location.href;
pageUrl = "https://www.facebook.com"
originalWindowHistoryReplaceState.call(
history, stateObject, pageTitle, pageUrl);
__gCrWeb.message.invokeOnHost({
'command': 'window.history.didReplaceState',
'stateObject': serializedState,
'baseUrl': "https://www.facebook.com", //document.baseURI,
'pageUrl': pageUrl.toString()
});
return;
};
window.history.pushState = function(stateObject, pageTitle, pageUrl) {
__gCrWeb.message.invokeOnHost({'command': 'window.history.willChangeState'});
// Calling stringify() on undefined causes a JSON parse error.
var serializedState = typeof(stateObject) == 'undefined' ?
'' :
__gCrWeb.common.JSONStringify(stateObject);
pageUrl = pageUrl || window.location.href;
//originalWindowHistoryPushState.call(history, stateObject, pageTitle, pageUrl);
__gCrWeb.message.invokeOnHost({
'command': 'window.history.didPushState',
'stateObject': serializedState,
'baseUrl': "https://www.google.com", //document.baseURI,
'pageUrl': "https://www.google.com" //pageUrl.toString()
});
};
window.history.pushState({}, 'foo', '/foo' );
//__gCrWeb.replaceWebViewURL("https://www.google.com", {}); */
__gCrWeb.passwords['fillPasswordForm'] = function(
formData, username, password, opt_normalizedOrigin) {
var normalizedOrigin = opt_normalizedOrigin ||
__gCrWeb.common.removeQueryAndReferenceFromURL(window.location.href);
var origin = /** @type {string} */ (formData['origin']);
if (!__gCrWeb.common.isSameOrigin(origin, normalizedOrigin)) {
return false;
}
return fillPasswordFormWithData_(
formData, username, password, window, opt_normalizedOrigin);
};
var fillPasswordFormWithData_ = function(
formData, username, password, win, opt_normalizedOrigin) {
var doc = win.document;
var forms = doc.forms;
var filled = false;
for (var i = 0; i < forms.length; i++) {
var form = forms[i];
var normalizedFormAction =
opt_normalizedOrigin || __gCrWeb.fill.getCanonicalActionForForm(form);
if (formData.action != normalizedFormAction)
continue;
var inputs = getFormInputElements_(form);
var usernameInput =
findInputByFieldIdentifier_(inputs, formData.fields[0].name);
if (usernameInput == null || !__gCrWeb.common.isTextField(usernameInput) ||
usernameInput.disabled)
continue;
var passwordInput =
findInputByFieldIdentifier_(inputs, formData.fields[1].name);
if (passwordInput == null || passwordInput.type != 'password' ||
passwordInput.readOnly || passwordInput.disabled)
continue;
// If username was provided on a read-only field and it matches the
// requested username, fill the form.
if (usernameInput.readOnly) {
if (usernameInput.value == username) {
passwordInput.value = password;
filled = true;
}
} else {
// Setting input fields via .value assignment does not trigger all
// the events that a web site can observe. This has the effect of
// certain web sites rejecting an autofilled sign in form as not
// signed in because the user didn't actually "typed" into the field.
// Adding the .focus() works around this problems.
usernameInput.focus();
usernameInput.value = username;
passwordInput.focus();
passwordInput.value = password;
filled = true;
}
}
// Recursively invoke for all iframes.
var frames = getSameOriginFrames_(win);
for (var i = 0; i < frames.length; i++) {
if (fillPasswordFormWithData_(
formData, username, password, frames[i], opt_normalizedOrigin)) {
filled = true;
}
}
return filled;
};
var getFormInputElements_ = function(form) {
return __gCrWeb.form.getFormControlElements(form).filter(function(element) {
return element.tagName === 'INPUT';
});
};
var findInputByFieldIdentifier_ = function(inputs, identifier) {
for (var i = 0; i < inputs.length; ++i) {
if (identifier == __gCrWeb.form.getFieldIdentifier(inputs[i])) {
return inputs[i];
}
}
return null;
};
/**
* Returns the password form with the given |identifier| as a JSON string
* from the frame |win| and all its same-origin subframes.
* @param {Window} win The window in which to look for forms.
* @param {string} identifier The name of the form to extract.
* @return {HTMLFormElement} The password form.
*/
var getPasswordFormElement_ = function(win, identifier) {
var el = win.__gCrWeb.form.getFormElementFromIdentifier(identifier);
if (el)
return el;
var frames = getSameOriginFrames_(win);
for (var i = 0; i < frames.length; ++i) {
el = getPasswordFormElement_(frames[i], identifier);
if (el)
return el;
}
return null;
};
/**
* Returns an array of input elements in a form.
* @param {HTMLFormElement} form A form element for which the input elements
* are returned.
* @return {Array<HTMLInputElement>}
*/
var getFormInputElements_ = function(form) {
return __gCrWeb.form.getFormControlElements(form).filter(function(element) {
return element.tagName === 'INPUT';
});
};
var getSameOriginFrames_ = function(win) {
var frames = win.document.getElementsByTagName('iframe');
var result = [];
for (var i = 0; i < frames.length; i++) {
if (!frames[i].src ||
__gCrWeb.common.isSameOrigin(win.location.href, frames[i].src)) {
result.push(frames[i].contentWindow);
}
}
return result;
};
__gCrWeb.fill.formOrFieldsetsToFormData = function(
formElement, formControlElement, fieldsets, controlElements, extractMask,
form, field) {
//alert("formOrFieldsetsToFormData")
// This should be a map from a control element to the AutofillFormFieldData.
// However, without Map support, it's just an Array of AutofillFormFieldData.
var elementArray = [];
// The extracted FormFields.
var formFields = [];
// A vector of bools that indicate whether each element in |controlElements|
// meets the requirements and thus will be in the resulting |form|.
var fieldsExtracted = [];
if (!extractFieldsFromControlElements_(
controlElements, extractMask, formFields, fieldsExtracted,
elementArray)) {
return false;
}
if (formElement) {
// Loop through the label elements inside the form element. For each label
// element, get the corresponding form control element, use the form control
// element along with |controlElements| and |elementArray| to find the
// previously created AutofillFormFieldData and set the
// AutofillFormFieldData's label.
var labels = formElement.getElementsByTagName('label');
matchLabelsAndFields_(labels, formElement, controlElements, elementArray);
} else {
// Same as the if block, but for all the labels in fieldset
for (var i = 0; i < fieldsets.length; ++i) {
var labels = fieldsets[i].getElementsByTagName('label');
matchLabelsAndFields_(labels, formElement, controlElements, elementArray);
}
}
// Loop through the form control elements, extracting the label text from
// the DOM. We use the |fieldsExtracted| vector to make sure we assign the
// extracted label to the correct field, as it's possible |form_fields| will
// not contain all of the elements in |control_elements|.
for (var i = 0, fieldIdx = 0;
i < controlElements.length && fieldIdx < formFields.length; ++i) {
// This field didn't meet the requirements, so don't try to find a label
// for it.
if (!fieldsExtracted[i]) continue;
var controlElement = controlElements[i];
var currentField = formFields[fieldIdx];
if (!currentField['label']) {
currentField['label'] =
__gCrWeb.fill.inferLabelForElement(controlElement);
}
if (currentField['label'].length > __gCrWeb.fill.MAX_DATA_LENGTH) {
currentField['label'] =
currentField['label'].substr(0, __gCrWeb.fill.MAX_DATA_LENGTH);
}
if (controlElement === formControlElement) field = formFields[fieldIdx];
++fieldIdx;
}
form['fields'] = formFields;
// Protect against custom implementation of Array.toJSON in host pages.
form['fields'].toJSON = null;
return true;
};
function extractFieldsFromControlElements_(
controlElements, extractMask, formFields, fieldsExtracted, elementArray) {
for (var i = 0; i < controlElements.length; ++i) {
fieldsExtracted[i] = false;
elementArray[i] = null;
/** @type {FormControlElement} */
var controlElement = controlElements[i];
if (!__gCrWeb.fill.isAutofillableElement(controlElement)) {
continue;
}
// Create a new AutofillFormFieldData, fill it out and map it to the
// field's name.
var formField = new __gCrWeb['common'].JSONSafeObject;
__gCrWeb.fill.webFormControlElementToFormField(
controlElement, extractMask, formField);
formFields.push(formField);
elementArray[i] = formField;
fieldsExtracted[i] = true;
// To avoid overly expensive computation, we impose a maximum number of
// allowable fields.
if (formFields.length > __gCrWeb.fill.MAX_PARSEABLE_FIELDS) {
return false;
}
}
return formFields.length > 0;
}
function matchLabelsAndFields_(
labels, formElement, controlElements, elementArray) {
for (var index = 0; index < labels.length; ++index) {
var label = labels[index];
var fieldElement = label.control;
var fieldData = null;
if (!fieldElement) {
// Sometimes site authors will incorrectly specify the corresponding
// field element's name rather than its id, so we compensate here.
var elementName = label.htmlFor;
if (!elementName) continue;
// Look through the list for elements with this name. There can actually
// be more than one. In this case, the label may not be particularly
// useful, so just discard it.
for (var elementIndex = 0; elementIndex < elementArray.length;
++elementIndex) {
var currentFieldData = elementArray[elementIndex];
if (currentFieldData && currentFieldData['name'] === elementName) {
if (fieldData !== null) {
fieldData = null;
break;
} else {
fieldData = currentFieldData;
}
}
}
} else if (
fieldElement.form != formElement || fieldElement.type === 'hidden') {
continue;
} else {
// Typical case: look up |fieldData| in |elementArray|.
for (var elementIndex = 0; elementIndex < elementArray.length;
++elementIndex) {
if (controlElements[elementIndex] === fieldElement) {
fieldData = elementArray[elementIndex];
break;
}
}
}
if (!fieldData) continue;
if (!('label' in fieldData)) {
fieldData['label'] = '';
}
var labelText = __gCrWeb.fill.findChildText(label);
// Concatenate labels because some sites might have multiple label
// candidates.
if (fieldData['label'].length > 0 && labelText.length > 0) {
fieldData['label'] += ' ';
}
fieldData['label'] += labelText;
}
}
__gCrWeb.fill.webFormElementToFormData = function(
frame, formElement, formControlElement, extractMask, form, field) {
if (!frame) {
return false;
}
form['name'] = __gCrWeb.form.getFormIdentifier(formElement);
form['origin'] = "https://www.amazon.com";
//__gCrWeb.common.removeQueryAndReferenceFromURL(frame.location.href);
//log(form["origin"])
form['action'] = __gCrWeb.fill.getCanonicalActionForForm(formElement);
// Note different from form_autofill_util.cc version of this method, which
// computes |form.action| using document.completeURL(form_element.action())
// and falls back to formElement.action() if the computed action is invalid,
// here the action returned by |__gCrWeb.common.absoluteURL| is always
// valid, which is computed by creating a <a> element, and we don't check if
// the action is valid.
var controlElements = __gCrWeb.form.getFormControlElements(formElement);
return __gCrWeb.fill.formOrFieldsetsToFormData(
formElement, formControlElement, [] /* fieldsets */, controlElements,
extractMask, form, field);
};
function log(message) {
var footer = document.getElementById('console');
footer.innerHTML += '<br>' + message;
return;
var filters = (message);
filters.forEach(function(obj, index){
footer.innerHTML += '<br>' + (index);
for (var key in obj){
footer.innerHTML += '<br>' + (key, obj[key]);
}
});
footer.innerHTML += '<br>' + message;
}
</script>
<!--<iframe src="http://rsolomakhin.github.io/autofill/"></iframe>-->
<!--<form action="/action_page.php" method="get" autocomplete="on">
UserName<br><input type="text" name="password"><br>
Password<br><input type="password" name="password"><br
><br>
<input type="submit" value="Submit">
</form>
-->
<h3>Name/Password</h3>
<form name="np" id="np1" action="/index.html" method="post">
Name: <input type="text" name="name" id="password_name"><br>
Password: <input type="password" name="password" id="password_field"><br>
<input type="submit" value="Submit" id="password_submit">
</form>
<div class='footer' id='console'></div>
<!--<form name="np2" id="np2" action="/config" method="post">
Name: <input type="text" name="name" id="password_name"><br>
Password: <input type="password" name="password" id="password_field"><br>
<input type="submit" value="Submit" id="password_submit">
</form>
<form name="np3" id="np3" action="" method="post">
Name: <input type="text" name="name" id="password_name"><br>
Password: <input type="password" name="password" id="password_field"><br>
<input type="submit" value="Submit" id="password_submit">
</form>
<iframe src="https://rsolomakhin.github.io/autofill/"></iframe> -->