-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
243 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "puppeteer-page-proxy", | ||
"description": "Additional Node.js module to use with 'puppeteer' for setting proxies per page basis.", | ||
"version": "1.2.6", | ||
"version": "1.2.7", | ||
"author": "Cuadrix <[email protected]> (https://github.com/Cuadrix)", | ||
"homepage": "https://github.com/Cuadrix/puppeteer-page-proxy", | ||
"main": "./src/index.js", | ||
|
@@ -10,8 +10,8 @@ | |
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type" : "git", | ||
"url" : "https://github.com/Cuadrix/puppeteer-page-proxy.git" | ||
"type": "git", | ||
"url": "https://github.com/Cuadrix/puppeteer-page-proxy.git" | ||
}, | ||
"keywords": [ | ||
"puppeteer", | ||
|
@@ -28,4 +28,4 @@ | |
"socks-proxy-agent": "^5.0.0", | ||
"tough-cookie": "^4.0.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,36 @@ | ||
const lookup = async (page, lookupService = "https://api.ipify.org?format=json", isJSON = true, timeout = 30000) => { | ||
const lookup = async (page, lookupService = "https://api64.ipify.org?format=json", isJSON = true, timeout = 30000) => { | ||
const doLookup = async () => { | ||
return await page.evaluate((lookupService, timeout, isJSON) => { | ||
return new Promise((resolve) => { | ||
const req = new XMLHttpRequest(); | ||
req.timeout = timeout; | ||
req.onload = () => { | ||
if (req.status >= 200 && req.status <= 299) { | ||
resolve(isJSON ? JSON.parse(req.responseText) : req.responseText); | ||
} else { | ||
resolve(onLookupFailed(`Request from ${window.location.href} to ${lookupService} failed with status code ${req.status}`)); | ||
} | ||
const request = new XMLHttpRequest(); | ||
request.timeout = timeout; | ||
request.onload = () => { | ||
if (request.status >= 200 && request.status <= 299) { | ||
resolve(isJSON ? JSON.parse(request.responseText) : request.responseText); | ||
} else {resolve(onLookupFailed( | ||
`Request from ${window.location.href} to ` + | ||
`${lookupService} failed with status code ${request.status}` | ||
))} | ||
}; | ||
req.ontimeout = (error) => { | ||
resolve(onLookupFailed(`Request from ${window.location.href} to ${lookupService} timed out -> ${req.timeout} ms`)); | ||
}; | ||
req.open("GET", lookupService, true); | ||
req.send(); | ||
request.ontimeout = (error) => {resolve(onLookupFailed( | ||
`Request from ${window.location.href} to ` + | ||
`${lookupService} timed out at ${request.timeout} ms` | ||
))}; | ||
request.open("GET", lookupService, true); | ||
request.send(); | ||
}); | ||
}, lookupService, timeout, isJSON); | ||
}; | ||
try { | ||
await page.setBypassCSP(true); | ||
const functionName = "onLookupFailed"; | ||
const functionName = "$ppp_on_lookup_failed"; | ||
if (!page._pageBindings.has(functionName)) { | ||
await page.exposeFunction(functionName, (reason) => { | ||
console.error(reason); | ||
return; | ||
await page.exposeFunction(functionName, (failReason) => { | ||
console.error(failReason); return; | ||
}); | ||
} | ||
return await doLookup(); | ||
} catch(error) { | ||
if (error.message.startsWith("Execution context was destroyed")) { | ||
return await doLookup(); | ||
} | ||
} | ||
} catch(error) {console.error(error)} | ||
}; | ||
|
||
module.exports = lookup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.