Add .attachDebuggger() method #51 #43

This commit is contained in:
Namhyeon Go 2022-05-30 18:18:32 +09:00 committed by GitHub
parent b72ff92ceb
commit 0eb1552687
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,11 +1,16 @@
////////////////////////////////////////////////////////////////////////
// HTTP API
////////////////////////////////////////////////////////////////////////
var SYS = require("lib/sys");
var FILE = require("lib/file");
var SHELL = require("lib/shell");
var RAND = require("lib/rand");
var BASE64 = require("lib/base64");
var OS_NAME = SYS.getOS();
var OS_ARCH = SYS.getArch();
var DEVICE_UUID = SYS.getUUID();
var HTTPObject = function(engine) {
this.interface = null;
this.contentType = "application/x-www-form-urlencoded";
@ -15,7 +20,7 @@ var HTTPObject = function(engine) {
this.headers = {};
this.parameters = {};
this.dataType = null;
this.userAgent = "WelsonJS/0.2.3-dev (https://github.com/gnh1201/welsonjs)";
this.userAgent = "WelsonJS/0.2.4-dev (" + OS_NAME + "; " + OS_ARCH + "; " + DEVICE_UUID + "; https://github.com/gnh1201/welsonjs)";
this.isAsync = false;
this.proxy = {
"enabled": false,
@ -708,18 +713,18 @@ var HTTPObject = function(engine) {
this.getFrameURLs = function() {
if (typeof this.responseBody !== "string") {
return [];
}
}
var urls = [];
var response = this.responseBody;
var pos = response.indexOf('<iframe ');
var response = this.responseBody;
var pos = response.indexOf('<iframe ');
while (pos > -1) {
var end = response.indexOf('</iframe>', pos);
var end = response.indexOf('</iframe>', pos);
if (response.indexOf('</iframe>', pos) < 0) {
continue;
}
}
var a = response.indexOf('src="', pos);
var b = response.indexOf('"', a + 5);
@ -733,6 +738,27 @@ var HTTPObject = function(engine) {
return urls;
};
this.attachDebugger = function(_debugger) {
var _debugger = _debugger.toUpperCase();
switch(_debugger) {
case "FIDDLER":
this.proxy.enabled = true;
this.proxy.port = 8866;
break;
case "MITMPROXY":
this.proxy.enabled = true;
this.proxy.port = 8080;
break;
default:
console.error("Not specified debugger");
}
return this;
};
this.create();
};