puppeteer-page-proxy
Advanced tools
Comparing version 1.2.0 to 1.2.2
# Change log | ||
### [1.2.2] - 2020-02-09 | ||
#### Patches | ||
- Fixed code indentation. | ||
- Updated examples. | ||
- Optimization. | ||
### [1.2.0] - 2020-02-09 | ||
@@ -3,0 +8,0 @@ #### Major changes |
{ | ||
"name": "puppeteer-page-proxy", | ||
"description": "Additional Node.js module to use with 'puppeteer' for setting proxies per page basis.", | ||
"version": "1.2.0", | ||
"version": "1.2.2", | ||
"author": "Cuadrix <cuadrix12000@gmail.com> (https://github.com/Cuadrix)", | ||
@@ -26,3 +26,3 @@ "homepage": "https://github.com/Cuadrix/puppeteer-page-proxy", | ||
"got": "^10.5.2", | ||
"http-proxy-agent": "^4.0.0", | ||
"http-proxy-agent": "^4.0.1", | ||
"https-proxy-agent": "^5.0.0", | ||
@@ -29,0 +29,0 @@ "socks-proxy-agent": "^5.0.0", |
@@ -13,3 +13,3 @@ const {setHeaders, setAgent, request} = require("../lib/request"); | ||
let page, req; | ||
if (param.constructor.name === "Request"){ | ||
if (param.constructor.name === "Request") { | ||
req = param; | ||
@@ -16,0 +16,0 @@ } |
module.exports = class CDP { | ||
static async Send(ws, command) { | ||
ws.send(JSON.stringify(command)); | ||
return new Promise(resolve => { | ||
ws.on("message", function handler(msg) { | ||
const response = JSON.parse(msg); | ||
if (response.id === command.id) { | ||
ws.removeListener("message", handler); | ||
resolve(response); | ||
} | ||
}); | ||
}); | ||
} | ||
static Target = { | ||
attachToTarget: async (ws, targetId) => { | ||
const result = (await this.Send(ws, { | ||
id: 1, | ||
method: "Target.attachToTarget", | ||
params: { | ||
targetId: targetId, | ||
flatten: true, | ||
} | ||
})).result; | ||
if (result) { | ||
return result.sessionId; | ||
} | ||
} | ||
}; | ||
static Network = { | ||
getCookies: async (ws, sessionId) => { | ||
const result = (await this.Send(ws, { | ||
sessionId, | ||
id: 2, | ||
method: "Network.getCookies" | ||
})).result; | ||
if (result) { | ||
return result.cookies; | ||
} | ||
} | ||
}; | ||
static async Send(ws, command) { | ||
ws.send(JSON.stringify(command)); | ||
return new Promise(resolve => { | ||
ws.on("message", function handler(msg) { | ||
const response = JSON.parse(msg); | ||
if (response.id === command.id) { | ||
ws.removeListener("message", handler); | ||
resolve(response); | ||
} | ||
}); | ||
}); | ||
} | ||
static Target = { | ||
attachToTarget: async (ws, targetId) => { | ||
const result = (await this.Send(ws, { | ||
id: 1, | ||
method: "Target.attachToTarget", | ||
params: { | ||
targetId: targetId, | ||
flatten: true, | ||
} | ||
})).result; | ||
if (result) { | ||
return result.sessionId; | ||
} | ||
} | ||
}; | ||
static Network = { | ||
getCookies: async (ws, sessionId) => { | ||
const result = (await this.Send(ws, { | ||
sessionId, | ||
id: 2, | ||
method: "Network.getCookies" | ||
})).result; | ||
if (result) { | ||
return result.cookies; | ||
} | ||
} | ||
}; | ||
} |
@@ -27,6 +27,6 @@ const got = require("got"); | ||
return new SocksProxyAgent(proxy); | ||
} | ||
} | ||
else if (url.startsWith("https")) { | ||
return new HttpsProxyAgent(proxy); | ||
} else { | ||
} else { | ||
return new HttpProxyAgent(proxy); | ||
@@ -33,0 +33,0 @@ } |
const url = require("url"); | ||
module.exports = (host) => { | ||
const proxy = url.parse(host); | ||
if (proxy.protocol == null | ||
|| !(/^((https?)|(socks[45]?)):?$/i.test(proxy.protocol)) | ||
|| proxy.hostname == null || proxy.hostname.length == 0 | ||
|| proxy.port == null || proxy.port < 0 || proxy.port > 65535) { | ||
throw new Error(`${host} -> Invalid proxy`); | ||
} | ||
const proxy = url.parse(host); | ||
if (proxy.protocol == null | ||
|| !(/^((https?)|(socks[45]?)):?$/i.test(proxy.protocol)) | ||
|| proxy.hostname == null || proxy.hostname.length == 0 | ||
|| proxy.port == null || proxy.port < 0 || proxy.port > 65535) { | ||
throw new Error(`${host} -> Invalid proxy`); | ||
} | ||
}; |
module.exports = (...args) => { | ||
let types = [ | ||
"undefined", "object", "boolean", "number", "bigint", "string", "symbol", "function" | ||
]; | ||
args.forEach((arg, index) => { | ||
if (arg.length < 2) { | ||
throw new Error("Too few arguments passed into the list"); | ||
} else if (arg.length > 3) { | ||
throw new Error("Too many arguments passed into the list"); | ||
} else { | ||
if (types.includes(arg[1])) { | ||
if (typeof arg[0] != arg[1]) { | ||
if (typeof arg[2] == "string" && arg[2].length > 0) { | ||
throw new TypeError(`@arg${index + 1}: ${arg[2]}`); | ||
} else { | ||
throw new TypeError(`@arg${index + 1}: Type: ${typeof arg[0]} -> expected ${arg[1]}`); | ||
} | ||
} | ||
} else { | ||
throw new Error(`@arg${index + 1}: '${arg[1]}' is not a valid data type`); | ||
} | ||
} | ||
}); | ||
let types = [ | ||
"undefined", "object", "boolean", "number", "bigint", "string", "symbol", "function" | ||
]; | ||
args.forEach((arg, index) => { | ||
if (arg.length < 2) { | ||
throw new Error("Too few arguments passed into the list"); | ||
} else if (arg.length > 3) { | ||
throw new Error("Too many arguments passed into the list"); | ||
} else { | ||
if (types.includes(arg[1])) { | ||
if (typeof arg[0] != arg[1]) { | ||
if (typeof arg[2] == "string" && arg[2].length > 0) { | ||
throw new TypeError(`@arg${index + 1}: ${arg[2]}`); | ||
} else { | ||
throw new TypeError(`@arg${index + 1}: Type: ${typeof arg[0]} -> expected ${arg[1]}`); | ||
} | ||
} | ||
} else { | ||
throw new Error(`@arg${index + 1}: '${arg[1]}' is not a valid data type`); | ||
} | ||
} | ||
}); | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
18645
2
138
Updatedhttp-proxy-agent@^4.0.1