mirror of
https://github.com/gnh1201/welsonjs.git
synced 2026-03-14 15:48:45 +00:00
Merge pull request #309 from gnh1201/dev
Improve error handling in sendPageRPC and getEvaluatedValue
This commit is contained in:
commit
bb1078dca8
|
|
@ -422,13 +422,13 @@ var ChromeObject = function() {
|
|||
};
|
||||
|
||||
this.sendPageRPC = function(method, params) {
|
||||
var result = null;
|
||||
var response = null;
|
||||
|
||||
try {
|
||||
if (this.pageId != "") {
|
||||
var url = "http://localhost:3000/devtools/page/" + this.pageId + "?port=" + this.debuggingPort;
|
||||
try {
|
||||
result = HTTP.create()
|
||||
response = HTTP.create()
|
||||
.setContentType("application/json")
|
||||
.setDataType("json")
|
||||
.open("POST", url)
|
||||
|
|
@ -440,9 +440,21 @@ var ChromeObject = function() {
|
|||
.send()
|
||||
.responseBody
|
||||
;
|
||||
|
||||
// response if error
|
||||
if ("result" in response) {
|
||||
(function(r) {
|
||||
if ("subtype" in r && r.subtype == "error") {
|
||||
console.warn(r.description);
|
||||
}
|
||||
})(response.result.result);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e.message);
|
||||
result = {};
|
||||
response = {
|
||||
error: true,
|
||||
message: e && e.message ? e.message : "Request failed"
|
||||
};
|
||||
}
|
||||
|
||||
pageEventId.set(pageEventId.get() + 1);
|
||||
|
|
@ -450,7 +462,7 @@ var ChromeObject = function() {
|
|||
} else {
|
||||
this.setPageId(null);
|
||||
if (this.pageId != "") {
|
||||
result = this.sendPageRPC(method, params);
|
||||
response = this.sendPageRPC(method, params);
|
||||
} else {
|
||||
console.error("Page not found");
|
||||
}
|
||||
|
|
@ -459,7 +471,7 @@ var ChromeObject = function() {
|
|||
console.log("ChromeObject.sendPageRPC() ->", e.message);
|
||||
}
|
||||
|
||||
return result;
|
||||
return response;
|
||||
};
|
||||
|
||||
this.navigate = function(url) {
|
||||
|
|
@ -495,7 +507,9 @@ var ChromeObject = function() {
|
|||
this.getEvaluatedValue = function(expression) {
|
||||
try {
|
||||
var response = this.evaluate(expression);
|
||||
return response.result.result.value;
|
||||
return (function(r) {
|
||||
return ("value" in r ? r.value : "");
|
||||
})(response.result.result);
|
||||
} catch (e) {
|
||||
console.error("ChromeObject.getEvaluatedValue() ->", e.message);
|
||||
return "";
|
||||
|
|
@ -1493,7 +1507,7 @@ exports.startDebugInPrivate = function(url, proxy, profileName, debuggingPort, i
|
|||
|
||||
exports.publisherName = publisherName;
|
||||
|
||||
exports.VERSIONINFO = "Chrome Web Browser Debugging Interface (chrome.js) version 0.5";
|
||||
exports.VERSIONINFO = "Chrome Web Browser Debugging Interface (chrome.js) version 0.5.2";
|
||||
exports.AUTHOR = "gnh1201@catswords.re.kr";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user