Update chrome.js

This commit is contained in:
Namhyeon Go 2021-06-21 02:54:46 +09:00 committed by GitHub
parent 331578452f
commit 5572edb03d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,9 @@ var FILE = require("lib/file");
var HTTP = require("lib/http");
var Websocket = require("lib/websocket");
// for remote debugging
var pageEventId = 0;
var ChromeObject = function() {
this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\Chrome\\Application";
this.binPath = SYS.getEnvString("PROGRAMFILES") + "\\Google\\:installedDir\\Application\\chrome.exe";
@ -23,7 +26,6 @@ var ChromeObject = function() {
// for remote debugging
this.debuggingPort = 0;
this.pageEventId = 1;
this.pageId = "";
this.ws = Websocket.create();
@ -196,7 +198,7 @@ var ChromeObject = function() {
this.getPageList = function() {
if (this.debuggingPort > 0) {
return HTTP.get("http://localhost:" + this.debuggingPort + "/json");
return HTTP.get("http://127.0.0.1:" + this.debuggingPort + "/json");
} else {
console.error("Remote debugging unavailable");
return [];
@ -224,12 +226,12 @@ var ChromeObject = function() {
this.sendPageRPC = function(method, params) {
if (this.pageId != "") {
this.ws.send("ws://localhost:" + this.debuggingPort + "/devtools/page/" + this.pageId, JSON.stringify({
"id": this.pageEventId,
this.ws.send("ws://127.0.0.1:" + this.debuggingPort + "/devtools/page/" + this.pageId, JSON.stringify({
"id": pageEventId,
"method": method,
"params": params
}));
this.pageEventId++;
pageEventId++;
console.info("ChromeObject().sendPageRPC() -> Sent");
} else {
console.error("pageId not specified");
@ -249,6 +251,10 @@ var ChromeObject = function() {
"expression": expression
});
};
this.focus = function() {
return this.evaluate("window.focus()");
};
};
exports.create = function() {